diff options
Diffstat (limited to 'src')
141 files changed, 1760 insertions, 1760 deletions
diff --git a/src/alloc.c b/src/alloc.c index 0cac457d4..8d4a19476 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -49,7 +49,7 @@ int git_allocator_setup(git_allocator *allocator) int git_win32_crtdbg_init_allocator(git_allocator *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; } #endif diff --git a/src/annotated_commit.c b/src/annotated_commit.c index 5ef2babec..5d4f37082 100644 --- a/src/annotated_commit.c +++ b/src/annotated_commit.c @@ -31,7 +31,7 @@ static int annotated_commit_init( *out = NULL; 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; @@ -45,7 +45,7 @@ static int annotated_commit_init( description = annotated_commit->id_str; annotated_commit->description = git__strdup(description); - GITERR_CHECK_ALLOC(annotated_commit->description); + GIT_ERROR_CHECK_ALLOC(annotated_commit->description); done: if (!error) @@ -140,7 +140,7 @@ int git_annotated_commit_from_ref( if (!error) { (*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); @@ -180,10 +180,10 @@ int git_annotated_commit_from_fetchhead( return -1; (*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); - GITERR_CHECK_ALLOC((*out)->remote_url); + GIT_ERROR_CHECK_ALLOC((*out)->remote_url); return 0; } diff --git a/src/apply.c b/src/apply.c index b21d83885..bd0ba6a89 100644 --- a/src/apply.c +++ b/src/apply.c @@ -25,7 +25,7 @@ #include "index.h" #define apply_err(...) \ - ( giterr_set(GITERR_PATCH, __VA_ARGS__), GIT_EAPPLYFAIL ) + ( git_error_set(GIT_ERROR_PATCH, __VA_ARGS__), GIT_EAPPLYFAIL ) typedef struct { /* The lines that we allocate ourself are allocated out of the pool. @@ -68,7 +68,7 @@ static int patch_image_init_fromstr( end++; line = git_pool_mallocz(&out->pool, 1); - GITERR_CHECK_ALLOC(line); + GIT_ERROR_CHECK_ALLOC(line); if (git_vector_insert(&out->lines, line) < 0) return -1; @@ -155,7 +155,7 @@ static int update_hunk( &image->lines, linenum, (prelen - postlen)); if (error) { - giterr_set_oom(); + git_error_set_oom(); return -1; } @@ -483,7 +483,7 @@ static int apply_one( postimage_reader, delta->old_file.path)) == 0) { skip_preimage = true; } else if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = 0; } else { goto done; @@ -777,7 +777,7 @@ int git_apply( assert(repo && diff); - GITERR_CHECK_VERSION( + GIT_ERROR_CHECK_VERSION( given_opts, GIT_APPLY_OPTIONS_VERSION, "git_apply_options"); if (given_opts) diff --git a/src/array.h b/src/array.h index 1d8a01c96..03537e796 100644 --- a/src/array.h +++ b/src/array.h @@ -15,7 +15,7 @@ * git_array_t(int) my_ints = GIT_ARRAY_INIT; * ... * int *i = git_array_alloc(my_ints); - * GITERR_CHECK_ALLOC(i); + * GIT_ERROR_CHECK_ALLOC(i); * ... * git_array_clear(my_ints); * @@ -36,7 +36,7 @@ #define git_array_clear(a) \ 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; diff --git a/src/attr.c b/src/attr.c index 9950e6f7d..1f2643345 100644 --- a/src/attr.c +++ b/src/attr.c @@ -135,7 +135,7 @@ int git_attr_get_many_with_session( goto cleanup; 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) { @@ -233,7 +233,7 @@ int git_attr_foreach( error = callback(assign->name, assign->value, payload); if (error) { - giterr_set_after_callback(error); + git_error_set_after_callback(error); goto cleanup; } } @@ -277,7 +277,7 @@ static int system_attr_file( error = git_sysdir_find_system_file(out, GIT_ATTR_FILE_SYSTEM); if (error == GIT_ENOTFOUND) - giterr_clear(); + git_error_clear(); return error; } @@ -286,7 +286,7 @@ static int system_attr_file( error = git_sysdir_find_system_file(&attr_session->sysdir, GIT_ATTR_FILE_SYSTEM); if (error == GIT_ENOTFOUND) - giterr_clear(); + git_error_clear(); else if (error) return error; @@ -377,12 +377,12 @@ int git_attr_add_macro( return error; macro = git__calloc(1, sizeof(git_attr_rule)); - GITERR_CHECK_ALLOC(macro); + GIT_ERROR_CHECK_ALLOC(macro); pool = &git_repository_attr_cache(repo)->pool; 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.flags = GIT_ATTR_FNMATCH_MACRO; @@ -532,7 +532,7 @@ static int collect_attr_files( info.flags = flags; info.workdir = workdir; 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; if (!strcmp(dir.ptr, ".")) diff --git a/src/attr_file.c b/src/attr_file.c index f43375568..bd69c631b 100644 --- a/src/attr_file.c +++ b/src/attr_file.c @@ -34,10 +34,10 @@ int git_attr_file__new( git_attr_file_source source) { 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) { - giterr_set(GITERR_OS, "failed to initialize lock"); + git_error_set(GIT_ERROR_OS, "failed to initialize lock"); git__free(attrs); return -1; } @@ -56,7 +56,7 @@ int git_attr_file__clear_rules(git_attr_file *file, bool need_lock) git_attr_rule *rule; 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; } @@ -147,7 +147,7 @@ int git_attr_file__load( break; } default: - giterr_set(GITERR_INVALID, "unknown file source %d", source); + git_error_set(GIT_ERROR_INVALID, "unknown file source %d", source); return -1; } @@ -219,7 +219,7 @@ int git_attr_file__out_of_date( } 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; } } @@ -245,7 +245,7 @@ int git_attr_file__parse_buffer( context = attrs->entry->path; 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; } @@ -751,7 +751,7 @@ int git_attr_assignment__parse( /* allocate assign if needed */ if (!assign) { assign = git__calloc(1, sizeof(git_attr_assignment)); - GITERR_CHECK_ALLOC(assign); + GIT_ERROR_CHECK_ALLOC(assign); GIT_REFCOUNT_INC(assign); } @@ -785,7 +785,7 @@ int git_attr_assignment__parse( /* allocate permanent storage for name */ 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 (*scan == '=') { @@ -794,7 +794,7 @@ int git_attr_assignment__parse( /* if we found a value, allocate permanent storage for it */ if (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); } } diff --git a/src/attrcache.c b/src/attrcache.c index 0f3e52572..cb8a4a4e9 100644 --- a/src/attrcache.c +++ b/src/attrcache.c @@ -18,7 +18,7 @@ GIT_INLINE(int) attr_cache_lock(git_attr_cache *cache) GIT_UNUSED(cache); /* avoid warning if threading is off */ 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 0; @@ -60,7 +60,7 @@ int git_attr_cache__alloc_file_entry( } ce = git_pool_mallocz(pool, (uint32_t)cachesize); - GITERR_CHECK_ALLOC(ce); + GIT_ERROR_CHECK_ALLOC(ce); if (baselen) { memcpy(ce->fullpath, base, baselen); @@ -250,7 +250,7 @@ int git_attr_cache__get( } /* no error if file simply doesn't exist */ if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = 0; } } @@ -374,11 +374,11 @@ int git_attr_cache__init(git_repository *repo) return 0; cache = git__calloc(1, sizeof(git_attr_cache)); - GITERR_CHECK_ALLOC(cache); + GIT_ERROR_CHECK_ALLOC(cache); /* set up lock */ 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); return -1; } @@ -443,7 +443,7 @@ int git_attr_cache__insert_macro(git_repository *repo, git_attr_rule *macro) return 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; } else { git_strmap_insert(macros, macro->match.pattern, macro, &error); diff --git a/src/blame.c b/src/blame.c index 78b39886c..4e9829506 100644 --- a/src/blame.c +++ b/src/blame.c @@ -272,7 +272,7 @@ static int index_blob_lines(git_blame *blame) while (len--) { if (bol) { i = git_array_alloc(blame->line_index); - GITERR_CHECK_ALLOC(i); + GIT_ERROR_CHECK_ALLOC(i); *i = buf - blame->final_buf; bol = 0; } @@ -282,7 +282,7 @@ static int index_blob_lines(git_blame *blame) } } i = git_array_alloc(blame->line_index); - GITERR_CHECK_ALLOC(i); + GIT_ERROR_CHECK_ALLOC(i); *i = buf - blame->final_buf; blame->num_lines = num + incomplete; return blame->num_lines; @@ -334,7 +334,7 @@ static int blame_internal(git_blame *blame) blame->final_buf_size = git_blob_rawsize(blame->final_blob); 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->lno = blame->options.min_line - 1; @@ -381,7 +381,7 @@ int git_blame_file( goto on_error; blame = git_blame__alloc(repo, normOptions, path); - GITERR_CHECK_ALLOC(blame); + GIT_ERROR_CHECK_ALLOC(blame); if ((error = load_blob(blame)) < 0) goto on_error; @@ -423,14 +423,14 @@ static int buffer_hunk_cb( if (!blame->current_hunk) { /* Line added at the end of the file */ 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); } 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 */ blame->current_hunk = split_hunk_in_vector(&blame->hunks, blame->current_hunk, 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; @@ -459,7 +459,7 @@ static int buffer_line_cb( /* Create a new buffer-blame hunk with this line */ shift_hunks_by(&blame->hunks, blame->current_diff_line, 1); 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); } @@ -500,12 +500,12 @@ int git_blame_buffer( assert(out && reference && buffer && buffer_len); 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 */ git_vector_foreach(&reference->hunks, i, hunk) { git_blame_hunk *h = dup_hunk(hunk); - GITERR_CHECK_ALLOC(h); + GIT_ERROR_CHECK_ALLOC(h); git_vector_insert(&blame->hunks, h); } diff --git a/src/blame_git.c b/src/blame_git.c index 552f3f35b..06e7d648e 100644 --- a/src/blame_git.c +++ b/src/blame_git.c @@ -46,10 +46,10 @@ static int make_origin(git_blame__origin **out, git_commit *commit, const char * path, GIT_OBJECT_BLOB)) < 0) return error; - GITERR_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, sizeof(*o), path_len); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1); o = git__calloc(1, alloc_len); - GITERR_CHECK_ALLOC(o); + GIT_ERROR_CHECK_ALLOC(o); o->commit = commit; o->blob = (git_blob *) blob; @@ -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 || 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; } @@ -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)); else { 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++) { diff --git a/src/blob.c b/src/blob.c index ef8a004ae..79748af22 100644 --- a/src/blob.c +++ b/src/blob.c @@ -116,7 +116,7 @@ static int write_file_stream( p_close(fd); 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; } @@ -158,11 +158,11 @@ static int write_symlink( int error; 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); 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); return -1; } @@ -206,7 +206,7 @@ int git_blob__create_from_paths( goto done; 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; goto done; } @@ -334,11 +334,11 @@ int git_blob_create_fromstream(git_writestream **out, git_repository *repo, cons assert(out && repo); stream = git__calloc(1, sizeof(blob_writestream)); - GITERR_CHECK_ALLOC(stream); + GIT_ERROR_CHECK_ALLOC(stream); if (hintpath) { stream->hintpath = git__strdup(hintpath); - GITERR_CHECK_ALLOC(stream->hintpath); + GIT_ERROR_CHECK_ALLOC(stream->hintpath); } stream->repo = repo; diff --git a/src/branch.c b/src/branch.c index c5d915247..61ed03e2e 100644 --- a/src/branch.c +++ b/src/branch.c @@ -34,8 +34,8 @@ static int retrieve_branch_reference( if ((error = git_buf_joinpath(&ref_name, prefix, branch_name)) < 0) /* OOM */; else if ((error = git_reference_lookup(&branch, repo, ref_name.ptr)) < 0) - giterr_set( - GITERR_REFERENCE, "cannot locate %s branch '%s'", + git_error_set( + GIT_ERROR_REFERENCE, "cannot locate %s branch '%s'", is_remote ? "remote-tracking" : "local", branch_name); *branch_reference_out = branch; /* will be NULL on error */ @@ -46,8 +46,8 @@ static int retrieve_branch_reference( static int not_a_local_branch(const char *reference_name) { - giterr_set( - GITERR_INVALID, + git_error_set( + GIT_ERROR_INVALID, "reference '%s' is not a local branch.", reference_name); return -1; } @@ -71,7 +71,7 @@ static int create_branch( assert(git_object_owner((const git_object *)commit) == repository); 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; goto cleanup; } @@ -88,7 +88,7 @@ static int create_branch( } 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); error = -1; goto cleanup; @@ -168,7 +168,7 @@ int git_branch_delete(git_reference *branch) assert(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)); return GIT_ENOTFOUND; } @@ -177,13 +177,13 @@ int git_branch_delete(git_reference *branch) return 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)); return -1; } 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)); return -1; } @@ -243,7 +243,7 @@ int git_branch_iterator_new( branch_iter *iter; iter = git__calloc(1, sizeof(branch_iter)); - GITERR_CHECK_ALLOC(iter); + GIT_ERROR_CHECK_ALLOC(iter); iter->flags = list_flags; @@ -344,7 +344,7 @@ int git_branch_name( } else if (git_reference_is_remote(ref)) { branch_name += strlen(GIT_REFS_REMOTES_DIR); } else { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "reference '%s' is neither a local nor a remote branch.", ref->name); return -1; } @@ -402,7 +402,7 @@ int git_branch_upstream_name( goto cleanup; 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); error = GIT_ENOTFOUND; goto cleanup; @@ -452,7 +452,7 @@ int git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *r return error; 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; git_buf_clear(buf); } @@ -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 */ 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); error = GIT_ERROR; goto cleanup; @@ -501,7 +501,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna } else { git_remote_free(remote); - giterr_set(GITERR_REFERENCE, + git_error_set(GIT_ERROR_REFERENCE, "reference '%s' is ambiguous", refname); error = GIT_EAMBIGUOUS; goto cleanup; @@ -515,7 +515,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna git_buf_clear(buf); error = git_buf_puts(buf, remote_name); } else { - giterr_set(GITERR_REFERENCE, + git_error_set(GIT_ERROR_REFERENCE, "could not determine remote for '%s'", refname); error = GIT_ENOTFOUND; } @@ -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) local = 0; else { - giterr_set(GITERR_REFERENCE, + git_error_set(GIT_ERROR_REFERENCE, "cannot set upstream for branch '%s'", shortname); return GIT_ENOTFOUND; } diff --git a/src/buf_text.c b/src/buf_text.c index fa7f16b81..88fcb87dd 100644 --- a/src/buf_text.c +++ b/src/buf_text.c @@ -29,7 +29,7 @@ int git_buf_text_puts_escaped( 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) return -1; @@ -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); /* 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) return -1; @@ -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); /* attempt to reduce reallocs while in the loop */ - GITERR_CHECK_ALLOC_ADD(&alloclen, src->size, src->size >> 4); - GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, src->size, src->size >> 4); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); if (git_buf_grow(tgt, alloclen) < 0) return -1; tgt->size = 0; @@ -135,7 +135,7 @@ int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src) if (copylen && next[-1] == '\r') copylen--; - GITERR_CHECK_ALLOC_ADD(&alloclen, copylen, 3); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, copylen, 3); if (git_buf_grow_by(tgt, alloclen) < 0) return -1; diff --git a/src/buffer.c b/src/buffer.c index 1361bc0a6..0cc7f2b35 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -43,7 +43,7 @@ int git_buf_try_grow( return -1; 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; } @@ -73,7 +73,7 @@ int git_buf_try_grow( if (mark_oom) buf->ptr = git_buf__oom; - giterr_set_oom(); + git_error_set_oom(); return -1; } @@ -161,7 +161,7 @@ int git_buf_set(git_buf *buf, const void *data, size_t len) git_buf_clear(buf); } else { if (data != buf->ptr) { - GITERR_CHECK_ALLOC_ADD(&alloclen, len, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1); ENSURE_SIZE(buf, alloclen); memmove(buf->ptr, data, len); } @@ -192,7 +192,7 @@ int git_buf_sets(git_buf *buf, const char *string) int git_buf_putc(git_buf *buf, char c) { 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); buf->ptr[buf->size++] = c; buf->ptr[buf->size] = '\0'; @@ -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) { size_t new_size; - GITERR_CHECK_ALLOC_ADD(&new_size, buf->size, len); - GITERR_CHECK_ALLOC_ADD(&new_size, new_size, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len); + GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1); ENSURE_SIZE(buf, new_size); memset(buf->ptr + buf->size, c, len); buf->size += len; @@ -218,8 +218,8 @@ int git_buf_put(git_buf *buf, const char *data, size_t len) assert(data); - GITERR_CHECK_ALLOC_ADD(&new_size, buf->size, len); - GITERR_CHECK_ALLOC_ADD(&new_size, new_size, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len); + GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1); ENSURE_SIZE(buf, new_size); memmove(buf->ptr + buf->size, data, len); buf->size += 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; size_t blocks = (len / 3) + !!extra, alloclen; - GITERR_CHECK_ALLOC_ADD(&blocks, blocks, 1); - GITERR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 4); - GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size); + GIT_ERROR_CHECK_ALLOC_ADD(&blocks, blocks, 1); + GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 4); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size); ENSURE_SIZE(buf, alloclen); 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) size_t orig_size = buf->size, new_size; if (len % 4) { - giterr_set(GITERR_INVALID, "invalid base64 input"); + git_error_set(GIT_ERROR_INVALID, "invalid base64 input"); return -1; } assert(len % 4 == 0); - GITERR_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, (len / 4 * 3), buf->size); + GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1); ENSURE_SIZE(buf, new_size); 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) buf->size = orig_size; buf->ptr[buf->size] = '\0'; - giterr_set(GITERR_INVALID, "invalid base64 input"); + git_error_set(GIT_ERROR_INVALID, "invalid base64 input"); return -1; } @@ -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; - GITERR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 5); - GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size); - GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); + GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 5); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); ENSURE_SIZE(buf, alloclen); @@ -408,12 +408,12 @@ int git_buf_decode_base85( if (base85_len % 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; } - GITERR_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, output_len, buf->size); + GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1); ENSURE_SIZE(buf, new_size); while (output_len) { @@ -456,7 +456,7 @@ on_error: buf->size = orig_size; buf->ptr[buf->size] = '\0'; - giterr_set(GITERR_INVALID, "invalid base85 input"); + git_error_set(GIT_ERROR_INVALID, "invalid base85 input"); return -1; } @@ -469,8 +469,8 @@ int git_buf_decode_percent( { size_t str_pos, new_size; - GITERR_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, buf->size, str_len); + GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1); ENSURE_SIZE(buf, new_size); 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) size_t expected_size, new_size; int len; - GITERR_CHECK_ALLOC_MULTIPLY(&expected_size, strlen(format), 2); - GITERR_CHECK_ALLOC_ADD(&expected_size, expected_size, buf->size); + GIT_ERROR_CHECK_ALLOC_MULTIPLY(&expected_size, strlen(format), 2); + GIT_ERROR_CHECK_ALLOC_ADD(&expected_size, expected_size, buf->size); ENSURE_SIZE(buf, expected_size); while (1) { @@ -522,8 +522,8 @@ int git_buf_vprintf(git_buf *buf, const char *format, va_list ap) break; } - GITERR_CHECK_ALLOC_ADD(&new_size, buf->size, len); - GITERR_CHECK_ALLOC_ADD(&new_size, new_size, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len); + GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1); ENSURE_SIZE(buf, new_size); } @@ -667,10 +667,10 @@ int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...) 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) - GITERR_CHECK_ALLOC_ADD(&total_size, total_size, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1); } va_end(ap); @@ -678,7 +678,7 @@ int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...) if (total_size == 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) return -1; @@ -758,9 +758,9 @@ int git_buf_join( if (str_a >= buf->ptr && str_a < buf->ptr + buf->size) offset_a = str_a - buf->ptr; - GITERR_CHECK_ALLOC_ADD(&alloc_len, strlen_a, strlen_b); - GITERR_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, strlen_a, strlen_b); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, need_sep); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1); ENSURE_SIZE(buf, alloc_len); /* fix up internal pointers */ @@ -810,11 +810,11 @@ int git_buf_join3( sep_b = (str_b[len_b - 1] != separator); } - GITERR_CHECK_ALLOC_ADD(&len_total, len_a, sep_a); - GITERR_CHECK_ALLOC_ADD(&len_total, len_total, len_b); - GITERR_CHECK_ALLOC_ADD(&len_total, len_total, sep_b); - GITERR_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_a, sep_a); + GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, len_b); + GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, sep_b); + GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, len_c); + GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, 1); ENSURE_SIZE(buf, len_total); tgt = buf->ptr; @@ -877,8 +877,8 @@ int git_buf_splice( /* Ported from git.git * 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); - GITERR_CHECK_ALLOC_ADD(&alloc_size, new_size, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&new_size, (buf->size - nb_to_remove), nb_to_insert); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, new_size, 1); ENSURE_SIZE(buf, alloc_size); memmove(splice_loc + nb_to_insert, @@ -995,14 +995,14 @@ int git_buf_unquote(git_buf *buf) /* \xyz digits convert to the char*/ case '0': case '1': case '2': case '3': if (j == buf->size-3) { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "truncated quoted character \\%c", ch); return -1; } if (buf->ptr[j+1] < '0' || buf->ptr[j+1] > '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", buf->ptr[j], buf->ptr[j+1], buf->ptr[j+2]); return -1; @@ -1015,7 +1015,7 @@ int git_buf_unquote(git_buf *buf) break; default: - giterr_set(GITERR_INVALID, "invalid quoted character \\%c", ch); + git_error_set(GIT_ERROR_INVALID, "invalid quoted character \\%c", ch); return -1; } } @@ -1029,6 +1029,6 @@ int git_buf_unquote(git_buf *buf) return 0; invalid: - giterr_set(GITERR_INVALID, "invalid quoted line"); + git_error_set(GIT_ERROR_INVALID, "invalid quoted line"); return -1; } diff --git a/src/cache.c b/src/cache.c index d786104b2..66107eaa9 100644 --- a/src/cache.c +++ b/src/cache.c @@ -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) { 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; } @@ -66,9 +66,9 @@ int git_cache_init(git_cache *cache) { memset(cache, 0, sizeof(*cache)); cache->map = git_oidmap_alloc(); - GITERR_CHECK_ALLOC(cache->map); + GIT_ERROR_CHECK_ALLOC(cache->map); 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 0; diff --git a/src/checkout.c b/src/checkout.c index a57e91924..fe020894a 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -146,7 +146,7 @@ static int checkout_notify( int error = data->opts.notify_cb( why, path, baseline, target, workdir, data->opts.notify_payload); - return giterr_set_after_callback_function( + return git_error_set_after_callback_function( error, "git_checkout notification"); } } @@ -193,7 +193,7 @@ static bool checkout_is_workdir_modified( bool rval = false; if (git_submodule_lookup(&sm, data->repo, wditem->path) < 0) { - giterr_clear(); + git_error_clear(); return true; } @@ -354,7 +354,7 @@ static bool wd_item_is_removable( static int checkout_queue_remove(checkout_data *data, const char *path) { char *copy = git_pool_strdup(&data->pool, path); - GITERR_CHECK_ALLOC(copy); + GIT_ERROR_CHECK_ALLOC(copy); return git_vector_insert(&data->removes, copy); } @@ -492,7 +492,7 @@ static int checkout_action_with_wd( switch (delta->status) { case GIT_DELTA_UNMODIFIED: /* case 14/15 or 33 */ if (checkout_is_workdir_modified(data, &delta->old_file, &delta->new_file, wd)) { - GITERR_CHECK_ERROR( + GIT_ERROR_CHECK_ERROR( checkout_notify(data, GIT_CHECKOUT_NOTIFY_DIRTY, delta, wd) ); *action = CHECKOUT_ACTION_IF(FORCE, UPDATE_BLOB, NONE); } @@ -561,7 +561,7 @@ static int checkout_action_with_wd_blocker( switch (delta->status) { case GIT_DELTA_UNMODIFIED: /* should show delta as dirty / deleted */ - GITERR_CHECK_ERROR( + GIT_ERROR_CHECK_ERROR( checkout_notify(data, GIT_CHECKOUT_NOTIFY_DIRTY, delta, wd) ); *action = CHECKOUT_ACTION_IF(FORCE, REMOVE_AND_UPDATE, NONE); break; @@ -594,9 +594,9 @@ static int checkout_action_with_wd_dir( switch (delta->status) { case GIT_DELTA_UNMODIFIED: /* case 19 or 24 (or 34 but not really) */ - GITERR_CHECK_ERROR( + GIT_ERROR_CHECK_ERROR( checkout_notify(data, GIT_CHECKOUT_NOTIFY_DIRTY, delta, NULL)); - GITERR_CHECK_ERROR( + GIT_ERROR_CHECK_ERROR( checkout_notify(data, GIT_CHECKOUT_NOTIFY_UNTRACKED, NULL, wd)); *action = CHECKOUT_ACTION_IF(FORCE, REMOVE_AND_UPDATE, NONE); break; @@ -611,7 +611,7 @@ static int checkout_action_with_wd_dir( break; case GIT_DELTA_DELETED: /* case 11 (and 27 for dir) */ if (delta->old_file.mode != GIT_FILEMODE_TREE) - GITERR_CHECK_ERROR( + GIT_ERROR_CHECK_ERROR( checkout_notify(data, GIT_CHECKOUT_NOTIFY_UNTRACKED, NULL, wd)); break; case GIT_DELTA_TYPECHANGE: /* case 24 or 31 */ @@ -902,7 +902,7 @@ static int checkout_conflict_append_update( int error; conflict = git__calloc(1, sizeof(checkout_conflictdata)); - GITERR_CHECK_ALLOC(conflict); + GIT_ERROR_CHECK_ALLOC(conflict); conflict->ancestor = ancestor; conflict->ours = ours; @@ -1044,20 +1044,20 @@ static int checkout_conflicts_load_byname_entry( *theirs_out = NULL; if (!name_entry->ancestor) { - giterr_set(GITERR_INDEX, "a NAME entry exists without an ancestor"); + git_error_set(GIT_ERROR_INDEX, "a NAME entry exists without an ancestor"); error = -1; goto done; } if (!name_entry->ours && !name_entry->theirs) { - giterr_set(GITERR_INDEX, "a NAME entry exists without an ours or theirs"); + git_error_set(GIT_ERROR_INDEX, "a NAME entry exists without an ours or theirs"); error = -1; goto done; } if ((ancestor = checkout_conflicts_search_ancestor(data, name_entry->ancestor)) == NULL) { - giterr_set(GITERR_INDEX, + git_error_set(GIT_ERROR_INDEX, "a NAME entry referenced ancestor entry '%s' which does not exist in the main index", name_entry->ancestor); error = -1; @@ -1069,7 +1069,7 @@ static int checkout_conflicts_load_byname_entry( ours = ancestor; else if ((ours = checkout_conflicts_search_branch(data, name_entry->ours)) == NULL || ours->ours == NULL) { - giterr_set(GITERR_INDEX, + git_error_set(GIT_ERROR_INDEX, "a NAME entry referenced our entry '%s' which does not exist in the main index", name_entry->ours); error = -1; @@ -1084,7 +1084,7 @@ static int checkout_conflicts_load_byname_entry( theirs = ours; else if ((theirs = checkout_conflicts_search_branch(data, name_entry->theirs)) == NULL || theirs->theirs == NULL) { - giterr_set(GITERR_INDEX, + git_error_set(GIT_ERROR_INDEX, "a NAME entry referenced their entry '%s' which does not exist in the main index", name_entry->theirs); error = -1; @@ -1183,7 +1183,7 @@ static int checkout_conflicts_mark_directoryfile( if ((error = git_index_find(&j, index, path)) < 0) { if (error == GIT_ENOTFOUND) - giterr_set(GITERR_INDEX, + git_error_set(GIT_ERROR_INDEX, "index inconsistency, could not find entry for expected conflict '%s'", path); goto done; @@ -1191,7 +1191,7 @@ static int checkout_conflicts_mark_directoryfile( for (; j < len; j++) { if ((entry = git_index_get_byindex(index, j)) == NULL) { - giterr_set(GITERR_INDEX, + git_error_set(GIT_ERROR_INDEX, "index inconsistency, truncated index while loading expected conflict '%s'", path); error = -1; goto done; @@ -1252,7 +1252,7 @@ static int checkout_conflict_append_remove( else abort(); - GITERR_CHECK_ALLOC(name); + GIT_ERROR_CHECK_ALLOC(name); return git_vector_insert(&data->remove_conflicts, (char *)name); } @@ -1277,14 +1277,14 @@ static int checkout_verify_paths( if (action & CHECKOUT_ACTION__REMOVE) { if (!git_path_isvalid(repo, delta->old_file.path, delta->old_file.mode, flags)) { - giterr_set(GITERR_CHECKOUT, "cannot remove invalid path '%s'", delta->old_file.path); + git_error_set(GIT_ERROR_CHECKOUT, "cannot remove invalid path '%s'", delta->old_file.path); return -1; } } if (action & ~CHECKOUT_ACTION__REMOVE) { if (!git_path_isvalid(repo, delta->new_file.path, delta->new_file.mode, flags)) { - giterr_set(GITERR_CHECKOUT, "cannot checkout to invalid path '%s'", delta->new_file.path); + git_error_set(GIT_ERROR_CHECKOUT, "cannot checkout to invalid path '%s'", delta->new_file.path); return -1; } } @@ -1354,7 +1354,7 @@ static int checkout_get_actions( if (counts[CHECKOUT_ACTION__CONFLICT] > 0 && (data->strategy & GIT_CHECKOUT_ALLOW_CONFLICTS) == 0) { - giterr_set(GITERR_CHECKOUT, "%"PRIuZ" %s checkout", + git_error_set(GIT_ERROR_CHECKOUT, "%"PRIuZ" %s checkout", counts[CHECKOUT_ACTION__CONFLICT], counts[CHECKOUT_ACTION__CONFLICT] == 1 ? "conflict prevents" : "conflicts prevent"); @@ -1453,10 +1453,10 @@ static int mkpath2file( */ error = git_futils_rmdir_r(path, NULL, GIT_RMDIR_REMOVE_FILES); } else if (errno != ENOENT) { - giterr_set(GITERR_OS, "failed to stat '%s'", path); + git_error_set(GIT_ERROR_OS, "failed to stat '%s'", path); return GIT_EEXISTS; } else { - giterr_clear(); + git_error_clear(); } } @@ -1477,7 +1477,7 @@ static int checkout_stream_write( int ret; if ((ret = p_write(stream->fd, buffer, len)) < 0) - giterr_set(GITERR_OS, "could not write to '%s'", stream->path); + git_error_set(GIT_ERROR_OS, "could not write to '%s'", stream->path); return ret; } @@ -1526,7 +1526,7 @@ static int blob_content_to_file( mode = GIT_FILEMODE_BLOB; if ((fd = p_open(path, flags, mode)) < 0) { - giterr_set(GITERR_OS, "could not open '%s' for writing", path); + git_error_set(GIT_ERROR_OS, "could not open '%s' for writing", path); return fd; } @@ -1563,7 +1563,7 @@ static int blob_content_to_file( data->perfdata.stat_calls++; if ((error = p_stat(path, st)) < 0) { - giterr_set(GITERR_OS, "failed to stat '%s'", path); + git_error_set(GIT_ERROR_OS, "failed to stat '%s'", path); return error; } @@ -1590,7 +1590,7 @@ static int blob_content_to_link( if (data->can_symlink) { if ((error = p_symlink(git_buf_cstr(&linktarget), path)) < 0) - giterr_set(GITERR_OS, "could not create symlink %s", path); + git_error_set(GIT_ERROR_OS, "could not create symlink %s", path); } else { error = git_futils_fake_symlink(git_buf_cstr(&linktarget), path); } @@ -1599,7 +1599,7 @@ static int blob_content_to_link( data->perfdata.stat_calls++; if ((error = p_lstat(path, st)) < 0) - giterr_set(GITERR_CHECKOUT, "could not stat symlink %s", path); + git_error_set(GIT_ERROR_CHECKOUT, "could not stat symlink %s", path); st->st_mode = GIT_FILEMODE_LINK; } @@ -1643,8 +1643,8 @@ static int checkout_submodule_update_index( data->perfdata.stat_calls++; if (p_stat(fullpath->ptr, &st) < 0) { - giterr_set( - GITERR_CHECKOUT, "could not stat submodule %s\n", file->path); + git_error_set( + GIT_ERROR_CHECKOUT, "could not stat submodule %s\n", file->path); return GIT_ENOTFOUND; } @@ -1675,7 +1675,7 @@ static int checkout_submodule( * have a .gitmodules - core Git just makes an empty directory */ if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); return checkout_submodule_update_index(data, file); } @@ -1717,7 +1717,7 @@ static int checkout_safe_for_update_only( return 0; /* otherwise, stat error and no update */ - giterr_set(GITERR_OS, "failed to stat '%s'", path); + git_error_set(GIT_ERROR_OS, "failed to stat '%s'", path); return -1; } @@ -1756,7 +1756,7 @@ static int checkout_write_content( if ((data->strategy & GIT_CHECKOUT_ALLOW_CONFLICTS) != 0 && (error == GIT_ENOTFOUND || error == GIT_EEXISTS)) { - giterr_clear(); + git_error_clear(); error = 0; } @@ -1863,7 +1863,7 @@ static int checkout_deferred_remove(git_repository *repo, const char *path) if (error == GIT_ENOTFOUND) { error = 0; - giterr_clear(); + git_error_clear(); } return error; @@ -1989,7 +1989,7 @@ static int checkout_path_suffixed(git_buf *path, const char *suffix) if (i == INT_MAX) { git_buf_truncate(path, path_len); - giterr_set(GITERR_CHECKOUT, "could not write '%s': working directory file exists", path->ptr); + git_error_set(GIT_ERROR_CHECKOUT, "could not write '%s': working directory file exists", path->ptr); return GIT_EEXISTS; } @@ -2123,7 +2123,7 @@ static int checkout_write_merge( goto done; if (result.path == NULL || result.mode == 0) { - giterr_set(GITERR_CHECKOUT, "could not merge contents of file"); + git_error_set(GIT_ERROR_CHECKOUT, "could not merge contents of file"); error = GIT_ECONFLICT; goto done; } @@ -2179,7 +2179,7 @@ static int checkout_conflict_add( int error = git_index_remove(data->index, conflict->path, 0); if (error == GIT_ENOTFOUND) - giterr_clear(); + git_error_clear(); else if (error < 0) return error; @@ -2370,7 +2370,7 @@ static int checkout_data_init( memset(data, 0, sizeof(*data)); if (!repo) { - giterr_set(GITERR_CHECKOUT, "cannot checkout nothing"); + git_error_set(GIT_ERROR_CHECKOUT, "cannot checkout nothing"); return -1; } @@ -2381,7 +2381,7 @@ static int checkout_data_init( data->repo = repo; data->target = target; - GITERR_CHECK_VERSION( + GIT_ERROR_CHECK_VERSION( proposed, GIT_CHECKOUT_OPTIONS_VERSION, "git_checkout_options"); if (!proposed) @@ -2424,7 +2424,7 @@ static int checkout_data_init( */ if (git_index_has_conflicts(data->index)) { error = GIT_ECONFLICT; - giterr_set(GITERR_CHECKOUT, + git_error_set(GIT_ERROR_CHECKOUT, "unresolved conflicts exist in the index"); goto cleanup; } @@ -2483,7 +2483,7 @@ static int checkout_data_init( if (error == GIT_EUNBORNBRANCH) { error = 0; - giterr_clear(); + git_error_clear(); } if (error < 0) @@ -2506,7 +2506,7 @@ static int checkout_data_init( else if (strcmp(conflict_style->value, "diff3") == 0) data->opts.checkout_strategy |= GIT_CHECKOUT_CONFLICT_STYLE_DIFF3; else { - giterr_set(GITERR_CHECKOUT, "unknown style '%s' given for 'merge.conflictstyle'", + git_error_set(GIT_ERROR_CHECKOUT, "unknown style '%s' given for 'merge.conflictstyle'", conflict_style->value); error = -1; git_config_entry_free(conflict_style); @@ -2688,7 +2688,7 @@ int git_checkout_index( git_iterator *index_i; if (!index && !repo) { - giterr_set(GITERR_CHECKOUT, + git_error_set(GIT_ERROR_CHECKOUT, "must provide either repository or index to checkout"); return -1; } @@ -2696,7 +2696,7 @@ int git_checkout_index( if (index && repo && git_index_owner(index) && git_index_owner(index) != repo) { - giterr_set(GITERR_CHECKOUT, + git_error_set(GIT_ERROR_CHECKOUT, "index to checkout does not match repository"); return -1; } else if(index && repo && !git_index_owner(index)) { @@ -2735,12 +2735,12 @@ int git_checkout_tree( git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; if (!treeish && !repo) { - giterr_set(GITERR_CHECKOUT, + git_error_set(GIT_ERROR_CHECKOUT, "must provide either repository or tree to checkout"); return -1; } if (treeish && repo && git_object_owner(treeish) != repo) { - giterr_set(GITERR_CHECKOUT, + git_error_set(GIT_ERROR_CHECKOUT, "object to checkout does not match repository"); return -1; } @@ -2750,16 +2750,16 @@ int git_checkout_tree( if (treeish) { if (git_object_peel((git_object **)&tree, treeish, GIT_OBJECT_TREE) < 0) { - giterr_set( - GITERR_CHECKOUT, "provided object cannot be peeled to a tree"); + git_error_set( + GIT_ERROR_CHECKOUT, "provided object cannot be peeled to a tree"); return -1; } } else { if ((error = checkout_lookup_head_tree(&tree, repo)) < 0) { if (error != GIT_EUNBORNBRANCH) - giterr_set( - GITERR_CHECKOUT, + git_error_set( + GIT_ERROR_CHECKOUT, "HEAD could not be peeled to a tree and no treeish given"); return error; } diff --git a/src/cherrypick.c b/src/cherrypick.c index ba404aca3..26935c6df 100644 --- a/src/cherrypick.c +++ b/src/cherrypick.c @@ -108,7 +108,7 @@ static int cherrypick_seterr(git_commit *commit, const char *fmt) { 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))); return -1; @@ -179,7 +179,7 @@ int git_cherrypick( 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) return error; diff --git a/src/clone.c b/src/clone.c index e2bf32069..8688da9e4 100644 --- a/src/clone.c +++ b/src/clone.c @@ -176,7 +176,7 @@ static int update_head_to_remote( refspec = git_remote__matching_refspec(remote, git_buf_cstr(&branch)); 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; goto cleanup; } @@ -332,7 +332,7 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch assert(repo && _remote); 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; } @@ -400,11 +400,11 @@ int git_clone( if (_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 */ 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); return GIT_EEXISTS; } @@ -441,14 +441,14 @@ int git_clone( if (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); repo = NULL; (void)git_futils_rmdir_r(local_path, NULL, rmdir_flags); - giterr_state_restore(&last_error); + git_error_state_restore(&last_error); } *out = repo; @@ -496,7 +496,7 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_ assert(repo && remote); 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; } diff --git a/src/commit.c b/src/commit.c index 3338b175d..513fdccaf 100644 --- a/src/commit.c +++ b/src/commit.c @@ -99,14 +99,14 @@ static int validate_tree_and_parents(git_array_oid_t *parents, git_repository *r } parent_cpy = git_array_alloc(*parents); - GITERR_CHECK_ALLOC(parent_cpy); + GIT_ERROR_CHECK_ALLOC(parent_cpy); git_oid_cpy(parent_cpy, parent); i++; } 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; goto on_error; } @@ -143,7 +143,7 @@ static int git_commit__create_internal( if (error < 0 && error != GIT_ENOTFOUND) return error; } - giterr_clear(); + git_error_clear(); if (ref) current_id = git_reference_target(ref); @@ -351,7 +351,7 @@ int git_commit_amend( if (!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_tree_free(old_tree); } else { @@ -365,7 +365,7 @@ int git_commit_amend( if (git_oid_cmp(git_commit_id(commit_to_amend), git_reference_target(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; } } @@ -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 */ 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 */ 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) while (git_oid__parse(&parent_id, &buffer, buffer_end, "parent ") == 0) { 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); } 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) return -1; @@ -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 */ 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) return -1; @@ -448,7 +448,7 @@ int git_commit__parse_raw(void *_commit, const char *data, size_t size) buffer += strlen("encoding "); 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') @@ -458,7 +458,7 @@ int git_commit__parse_raw(void *_commit, const char *data, size_t size) header_len = buffer - buffer_start; 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 */ buffer = buffer_start + header_len + 1; @@ -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); else commit->raw_message = git__strdup(""); - GITERR_CHECK_ALLOC(commit->raw_message); + GIT_ERROR_CHECK_ALLOC(commit->raw_message); return 0; 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; } @@ -610,7 +610,7 @@ int git_commit_parent( parent_id = git_commit_parent_id(commit, n); 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; } @@ -699,14 +699,14 @@ int git_commit_header_field(git_buf *out, const git_commit *commit, const char * 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; malformed: - giterr_set(GITERR_OBJECT, "malformed header"); + git_error_set(GIT_ERROR_OBJECT, "malformed header"); return -1; oom: - giterr_set_oom(); + git_error_set_oom(); return -1; } @@ -731,7 +731,7 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r return error; 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; goto cleanup; } @@ -783,16 +783,16 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r 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; goto cleanup; malformed: - giterr_set(GITERR_OBJECT, "malformed header"); + git_error_set(GIT_ERROR_OBJECT, "malformed header"); error = -1; goto cleanup; oom: - giterr_set_oom(); + git_error_set_oom(); error = -1; goto cleanup; @@ -872,7 +872,7 @@ int git_commit_create_with_signature( /* We start by identifying the end of the commit header */ header_end = strstr(commit_content, "\n\n"); if (!header_end) { - giterr_set(GITERR_INVALID, "malformed commit contents"); + git_error_set(GIT_ERROR_INVALID, "malformed commit contents"); return -1; } diff --git a/src/commit_list.c b/src/commit_list.c index 078a87bc0..5496dca44 100644 --- a/src/commit_list.c +++ b/src/commit_list.c @@ -61,7 +61,7 @@ static int commit_error(git_commit_list_node *commit, const char *msg) git_oid_fmt(commit_oid, &commit->oid); 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; } @@ -126,7 +126,7 @@ static int commit_quick_parse( } commit->parents = alloc_parents(walk, commit, parents); - GITERR_CHECK_ALLOC(commit->parents); + GIT_ERROR_CHECK_ALLOC(commit->parents); buffer = parents_start; for (i = 0; i < parents; ++i) { @@ -193,7 +193,7 @@ int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit) return error; 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; } else error = commit_quick_parse( diff --git a/src/common.h b/src/common.h index cb980c107..6e1eac834 100644 --- a/src/common.h +++ b/src/common.h @@ -89,30 +89,30 @@ /** * 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. */ -#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. */ -#define GITERR_CHECK_ERROR(code) \ +#define GIT_ERROR_CHECK_ERROR(code) \ do { int _err = (code); if (_err) return _err; } while (0) /** * 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 * 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. @@ -122,35 +122,35 @@ int giterr_set_regex(const regex_t *regex, int error_code); * * @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) { if (error_code) { - const git_error *e = giterr_last(); + const git_error *e = git_error_last(); 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); } return error_code; } #ifdef GIT_WIN32 -#define giterr_set_after_callback(code) \ - giterr_set_after_callback_function((code), __FUNCTION__) +#define git_error_set_after_callback(code) \ + git_error_set_after_callback_function((code), __FUNCTION__) #else -#define giterr_set_after_callback(code) \ - giterr_set_after_callback_function((code), __func__) +#define git_error_set_after_callback(code) \ + git_error_set_after_callback_function((code), __func__) #endif /** * 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. */ -void giterr_system_set(int code); +void git_error_system_set(int code); /** * Structure to preserve libgit2 error state @@ -166,20 +166,20 @@ typedef struct { * If `error_code` is zero, this does not clear the current error state. * 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. */ -extern int giterr_state_restore(git_error_state *state); +extern int git_error_state_restore(git_error_state *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 */ -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; @@ -190,10 +190,10 @@ GIT_INLINE(int) giterr__check_version(const void *structure, unsigned int expect if (actual > 0 && actual <= expected_max) 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; } -#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. @@ -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 { \ 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) /** Check for additive overflow, setting an error if would occur. */ #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. */ #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. */ -#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; } -#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) || \ 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) || \ GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \ 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) || \ GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \ GIT_ADD_SIZET_OVERFLOW(out, *(out), four) || \ GIT_ADD_SIZET_OVERFLOW(out, *(out), five)) { return -1; } /** 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; } -/* 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" diff --git a/src/config.c b/src/config.c index 30d97306c..fce1aad3b 100644 --- a/src/config.c +++ b/src/config.c @@ -81,7 +81,7 @@ int git_config_new(git_config **out) git_config *cfg; cfg = git__malloc(sizeof(git_config)); - GITERR_CHECK_ALLOC(cfg); + GIT_ERROR_CHECK_ALLOC(cfg); memset(cfg, 0x0, sizeof(git_config)); @@ -110,7 +110,7 @@ int git_config_add_file_ondisk( res = p_stat(path, &st); 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; } @@ -203,7 +203,7 @@ static int find_backend_by_level( } if (pos == -1) { - giterr_set(GITERR_CONFIG, + git_error_set(GIT_ERROR_CONFIG, "no configuration exists for the given level '%i'", (int)level); return GIT_ENOTFOUND; } @@ -219,7 +219,7 @@ static int duplicate_level(void **old_raw, void *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; } @@ -316,13 +316,13 @@ int git_config_add_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) return result; internal = git__malloc(sizeof(backend_internal)); - GITERR_CHECK_ALLOC(internal); + GIT_ERROR_CHECK_ALLOC(internal); memset(internal, 0x0, sizeof(backend_internal)); @@ -456,7 +456,7 @@ int git_config_iterator_new(git_config_iterator **out, const git_config *cfg) all_iter *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.next = all_iter_next; @@ -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); 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) { - giterr_set_regex(&iter->regex, result); + git_error_set_regex(&iter->regex, result); git__free(iter); return -1; } @@ -517,7 +517,7 @@ int git_config_backend_foreach_match( if (regexp != NULL) { if ((error = p_regcomp(®ex, regexp, REG_EXTENDED)) != 0) { - giterr_set_regex(®ex, error); + git_error_set_regex(®ex, error); regfree(®ex); return -1; } @@ -535,7 +535,7 @@ int git_config_backend_foreach_match( /* abort iterator on non-zero return value */ if ((error = cb(entry, payload)) != 0) { - giterr_set_after_callback(error); + git_error_set_after_callback(error); break; } } @@ -563,7 +563,7 @@ int git_config_foreach_match( while (!(error = git_config_next(&entry, iter))) { if ((error = cb(entry, payload)) != 0) { - giterr_set_after_callback(error); + git_error_set_after_callback(error); break; } } @@ -599,7 +599,7 @@ static int get_backend_for_use(git_config_backend **out, *out = NULL; 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", uses[use], name); return GIT_ENOTFOUND; @@ -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", uses[use], name); return GIT_ENOTFOUND; @@ -651,7 +651,7 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value) git_config_backend *backend; 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; } @@ -703,7 +703,7 @@ int git_config__update_entry( 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; } @@ -750,7 +750,7 @@ cleanup: if (res == GIT_ENOTFOUND) res = (want_errors > GET_ALL_ERRORS) ? 0 : config_error_notfound(name); else if (res && (want_errors == GET_NO_ERRORS)) { - giterr_clear(); + git_error_clear(); res = 0; } @@ -871,7 +871,7 @@ int git_config_get_string( int ret; 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; } @@ -925,7 +925,7 @@ int git_config__get_bool_force( get_entry(&entry, cfg, key, false, GET_NO_ERRORS); if (entry && git_config_parse_bool(&val, entry->value) < 0) - giterr_clear(); + git_error_clear(); git_config_entry_free(entry); return val; @@ -940,7 +940,7 @@ int git_config__get_int_force( get_entry(&entry, cfg, key, false, GET_NO_ERRORS); if (entry && git_config_parse_int32(&val, entry->value) < 0) - giterr_clear(); + git_error_clear(); git_config_entry_free(entry); return (int)val; @@ -962,7 +962,7 @@ int git_config_get_multivar_foreach( found = 1; if ((err = cb(entry, payload)) != 0) { - giterr_set_after_callback(err); + git_error_set_after_callback(err); break; } } @@ -1026,7 +1026,7 @@ int git_config_multivar_iterator_new(git_config_iterator **out, const git_config return error; 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) goto on_error; @@ -1034,7 +1034,7 @@ int git_config_multivar_iterator_new(git_config_iterator **out, const git_config if (regexp != NULL) { error = p_regcomp(&iter->regex, regexp, REG_EXTENDED); if (error != 0) { - giterr_set_regex(&iter->regex, error); + git_error_set_regex(&iter->regex, error); error = -1; regfree(&iter->regex); goto on_error; @@ -1188,7 +1188,7 @@ int git_config_lock(git_transaction **out, git_config *cfg) internal = git_vector_get(&cfg->backends, 0); 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; } backend = internal->backend; @@ -1208,7 +1208,7 @@ int git_config_unlock(git_config *cfg, int commit) internal = git_vector_get(&cfg->backends, 0); 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; } @@ -1263,7 +1263,7 @@ int git_config_lookup_map_value( } fail_parse: - giterr_set(GITERR_CONFIG, "failed to map '%s'", value); + git_error_set(GIT_ERROR_CONFIG, "failed to map '%s'", value); return -1; } @@ -1283,7 +1283,7 @@ int git_config_lookup_map_enum(git_cvar_t *type_out, const char **str_out, return 0; } - giterr_set(GITERR_CONFIG, "invalid enum value"); + git_error_set(GIT_ERROR_CONFIG, "invalid enum value"); return GIT_ENOTFOUND; } @@ -1297,7 +1297,7 @@ int git_config_parse_bool(int *out, const char *value) 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; } @@ -1340,7 +1340,7 @@ int git_config_parse_int64(int64_t *out, const char *value) } 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; } @@ -1360,7 +1360,7 @@ int git_config_parse_int32(int32_t *out, const char *value) return 0; 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; } @@ -1372,7 +1372,7 @@ int git_config_parse_path(git_buf *out, const char *value) if (value[0] == '~') { 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; } @@ -1414,7 +1414,7 @@ int git_config__normalize_name(const char *in, char **out) assert(in && out); name = git__strdup(in); - GITERR_CHECK_ALLOC(name); + GIT_ERROR_CHECK_ALLOC(name); fdot = strchr(name, '.'); ldot = strrchr(name, '.'); @@ -1437,7 +1437,7 @@ int git_config__normalize_name(const char *in, char **out) invalid: 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; } @@ -1498,8 +1498,8 @@ int git_config_rename_section( if (new_section_name != NULL && (error = normalize_section(replace.ptr, strchr(replace.ptr, '.'))) < 0) { - giterr_set( - GITERR_CONFIG, "invalid config section '%s'", new_section_name); + git_error_set( + GIT_ERROR_CONFIG, "invalid config section '%s'", new_section_name); goto cleanup; } diff --git a/src/config_entries.c b/src/config_entries.c index fdbf79869..f6277bcc7 100644 --- a/src/config_entries.c +++ b/src/config_entries.c @@ -56,7 +56,7 @@ int git_config_entries_new(git_config_entries **out) int error; entries = git__calloc(1, sizeof(git_config_entries)); - GITERR_CHECK_ALLOC(entries); + GIT_ERROR_CHECK_ALLOC(entries); GIT_REFCOUNT_INC(entries); 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 dup = git__calloc(1, sizeof(git_config_entry)); dup->name = git__strdup(head->entry->name); - GITERR_CHECK_ALLOC(dup->name); + GIT_ERROR_CHECK_ALLOC(dup->name); if (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->include_depth = head->entry->include_depth; @@ -136,7 +136,7 @@ int git_config_entries_append(git_config_entries *entries, git_config_entry *ent size_t pos; var = git__calloc(1, sizeof(config_entry_list)); - GITERR_CHECK_ALLOC(var); + GIT_ERROR_CHECK_ALLOC(var); var->entry = entry; 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 } var = git__calloc(1, sizeof(config_entry_list)); - GITERR_CHECK_ALLOC(var); + GIT_ERROR_CHECK_ALLOC(var); var->entry = entry; 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 return error; 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; } 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; } @@ -246,7 +246,7 @@ int git_config_entries_iterator_new(git_config_iterator **out, git_config_entrie config_entries_iterator *it; 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.free = config_iterator_free; it->head = entries->list; diff --git a/src/config_file.c b/src/config_file.c index 57db97d8b..26c9e5ed2 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -69,7 +69,7 @@ static int config_snapshot(git_config_backend **out, git_config_backend *in); 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; } @@ -83,7 +83,7 @@ static git_config_entries *diskfile_entries_take(diskfile_header *h) git_config_entries *entries; 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; } @@ -196,7 +196,7 @@ static int config_refresh(git_config_backend *cfg) goto out; 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; } @@ -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 */ if (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) @@ -339,7 +339,7 @@ static int config_set_multivar( result = p_regcomp(&preg, regexp, REG_EXTENDED); if (result != 0) { - giterr_set_regex(&preg, result); + git_error_set_regex(&preg, result); result = -1; goto out; } @@ -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 */ if ((error = git_config_entries_get_unique(&entry, entries, key)) < 0) { 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; } @@ -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_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; } if ((result = p_regcomp(&preg, regexp, REG_EXTENDED)) != 0) { - giterr_set_regex(&preg, result); + git_error_set_regex(&preg, result); result = -1; goto out; } @@ -473,13 +473,13 @@ int git_config_backend_from_file(git_config_backend **out, const char *path) diskfile_backend *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; git_mutex_init(&backend->header.values_mutex); 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); backend->header.parent.open = config_open; @@ -590,7 +590,7 @@ static int config_snapshot(git_config_backend **out, git_config_backend *in) diskfile_readonly_backend *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; git_mutex_init(&backend->header.values_mutex); @@ -686,7 +686,7 @@ static int parse_include(git_config_parser *reader, include, parse_data->level, parse_data->depth+1); if (result == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); result = 0; } @@ -828,7 +828,7 @@ static int read_on_variable( return -1; entry = git__calloc(1, sizeof(git_config_entry)); - GITERR_CHECK_ALLOC(entry); + GIT_ERROR_CHECK_ALLOC(entry); entry->name = git_buf_detach(&buf); entry->value = var_value ? git__strdup(var_value) : NULL; entry->level = parse_data->level; @@ -863,7 +863,7 @@ static int config_read( int error; 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; } @@ -911,7 +911,7 @@ static int write_section(git_buf *fbuf, const char *key) char *escaped; git_buf_put(&buf, key, dot - key); escaped = escape_value(dot + 1); - GITERR_CHECK_ALLOC(escaped); + GIT_ERROR_CHECK_ALLOC(escaped); git_buf_printf(&buf, " \"%s\"", escaped); git__free(escaped); } @@ -1156,12 +1156,12 @@ static int config_write(diskfile_backend *cfg, const char *orig_key, const char ldot = strrchr(key, '.'); name = ldot + 1; section = git__strndup(key, ldot - key); - GITERR_CHECK_ALLOC(section); + GIT_ERROR_CHECK_ALLOC(section); ldot = strrchr(orig_key, '.'); orig_name = ldot + 1; orig_section = git__strndup(orig_key, ldot - orig_key); - GITERR_CHECK_ALLOC(orig_section); + GIT_ERROR_CHECK_ALLOC(orig_section); write_data.buf = &buf; git_buf_init(&write_data.buffered_comment, 0); diff --git a/src/config_mem.c b/src/config_mem.c index 18e405ad5..c2ecfda12 100644 --- a/src/config_mem.c +++ b/src/config_mem.c @@ -24,7 +24,7 @@ typedef struct { 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; } @@ -63,7 +63,7 @@ static int read_variable_cb( return -1; entry = git__calloc(1, sizeof(git_config_entry)); - GITERR_CHECK_ALLOC(entry); + GIT_ERROR_CHECK_ALLOC(entry); entry->name = git_buf_detach(&buf); entry->value = var_value ? git__strdup(var_value) : NULL; entry->level = parse_data->level; @@ -170,7 +170,7 @@ static int config_memory_snapshot(git_config_backend **out, git_config_backend * { GIT_UNUSED(out); 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; } @@ -191,7 +191,7 @@ int git_config_backend_from_string(git_config_backend **out, const char *cfg, si config_memory_backend *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) { git__free(backend); diff --git a/src/config_parse.c b/src/config_parse.c index a9c7c5242..ab2fb9867 100644 --- a/src/config_parse.c +++ b/src/config_parse.c @@ -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) { 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); } @@ -87,8 +87,8 @@ static int parse_section_header_ext(git_config_parser *reader, const char *line, goto end_error; } - GITERR_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, base_name_len, quoted_len); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2); if (git_buf_grow(&buf, alloc_len) < 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) 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); - GITERR_CHECK_ALLOC(name); + GIT_ERROR_CHECK_ALLOC(name); name_length = 0; pos = 0; @@ -304,7 +304,7 @@ static int unescape_line( *fixed++ = git_config_escaped[esc - git_config_escapes]; } else { 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; } } @@ -330,7 +330,7 @@ static int parse_multiline_variable(git_config_parser *reader, git_buf *value, i /* Check that the next line exists */ git_parse_advance_line(&reader->ctx); 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. @@ -420,7 +420,7 @@ static int parse_variable(git_config_parser *reader, char **var_name, char **var git_parse_advance_ws(&reader->ctx); 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); diff --git a/src/crlf.c b/src/crlf.c index df8806f0e..80441e7e3 100644 --- a/src/crlf.c +++ b/src/crlf.c @@ -85,7 +85,7 @@ static int has_cr_in_index(const git_filter_source *src) return false; if (git_repository_index__weakptr(&index, repo) < 0) { - giterr_clear(); + git_error_clear(); return false; } @@ -170,12 +170,12 @@ GIT_INLINE(int) check_safecrlf( /* TODO: issue a warning when available */ } else { if (filename && *filename) - giterr_set( - GITERR_FILTER, "CRLF would be replaced by LF in '%s'", + git_error_set( + GIT_ERROR_FILTER, "CRLF would be replaced by LF in '%s'", filename); else - giterr_set( - GITERR_FILTER, "CRLF would be replaced by LF"); + git_error_set( + GIT_ERROR_FILTER, "CRLF would be replaced by LF"); return -1; } @@ -190,12 +190,12 @@ GIT_INLINE(int) check_safecrlf( /* TODO: issue a warning when available */ } else { if (filename && *filename) - giterr_set( - GITERR_FILTER, "LF would be replaced by CRLF in '%s'", + git_error_set( + GIT_ERROR_FILTER, "LF would be replaced by CRLF in '%s'", filename); else - giterr_set( - GITERR_FILTER, "LF would be replaced by CRLF"); + git_error_set( + GIT_ERROR_FILTER, "LF would be replaced by CRLF"); return -1; } @@ -360,7 +360,7 @@ static int crlf_check( return GIT_PASSTHROUGH; *payload = git__malloc(sizeof(ca)); - GITERR_CHECK_ALLOC(*payload); + GIT_ERROR_CHECK_ALLOC(*payload); memcpy(*payload, &ca, sizeof(ca)); return 0; diff --git a/src/delta.c b/src/delta.c index b9352b8ee..9e8d1c030 100644 --- a/src/delta.c +++ b/src/delta.c @@ -124,19 +124,19 @@ static int lookup_index_alloc( { size_t entries_len, hash_len, index_len; - GITERR_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(&entries_len, entries, 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); - GITERR_CHECK_ALLOC_ADD(&index_len, index_len, hash_len); + GIT_ERROR_CHECK_ALLOC_ADD(&index_len, sizeof(struct git_delta_index), entries_len); + GIT_ERROR_CHECK_ALLOC_ADD(&index_len, index_len, hash_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; } *out = git__malloc(index_len); - GITERR_CHECK_ALLOC(*out); + GIT_ERROR_CHECK_ALLOC(*out); *out_len = index_len; return 0; @@ -291,7 +291,7 @@ int git_delta_create_from_index( if (max_size && bufsize >= max_size) bufsize = (unsigned int)(max_size + MAX_OP_SIZE + 1); buf = git__malloc(bufsize); - GITERR_CHECK_ALLOC(buf); + GIT_ERROR_CHECK_ALLOC(buf); /* store reference buffer size */ i = index->src_size; @@ -438,7 +438,7 @@ int git_delta_create_from_index( buf[bufpos - inscnt - 1] = inscnt; 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); return GIT_EBUFS; } @@ -466,7 +466,7 @@ static int hdr_sz( do { if (d == end) { - giterr_set(GITERR_INVALID, "truncated delta"); + git_error_set(GIT_ERROR_INVALID, "truncated delta"); return -1; } @@ -545,18 +545,18 @@ int git_delta_apply( * base object, resulting in data corruption or segfault. */ 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; } 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; } - 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); - GITERR_CHECK_ALLOC(res_dp); + GIT_ERROR_CHECK_ALLOC(res_dp); res_dp[res_sz] = '\0'; *out = res_dp; @@ -616,6 +616,6 @@ fail: *out = NULL; *out_len = 0; - giterr_set(GITERR_INVALID, "failed to apply delta"); + git_error_set(GIT_ERROR_INVALID, "failed to apply delta"); return -1; } diff --git a/src/describe.c b/src/describe.c index cf2c72841..7e57d64e7 100644 --- a/src/describe.c +++ b/src/describe.c @@ -108,7 +108,7 @@ static int add_to_known_names( if (replace_name(&tag, repo, e, prio, sha1)) { if (!found) { e = git__malloc(sizeof(struct commit_name)); - GITERR_CHECK_ALLOC(e); + GIT_ERROR_CHECK_ALLOC(e); e->path = NULL; e->tag = NULL; @@ -191,7 +191,7 @@ static int commit_name_dup(struct commit_name **out, struct commit_name *in) struct commit_name *name; name = git__malloc(sizeof(struct commit_name)); - GITERR_CHECK_ALLOC(name); + GIT_ERROR_CHECK_ALLOC(name); memcpy(name, in, sizeof(struct commit_name)); name->tag = NULL; @@ -201,7 +201,7 @@ static int commit_name_dup(struct commit_name **out, struct commit_name *in) return -1; name->path = git__strdup(in->path); - GITERR_CHECK_ALLOC(name->path); + GIT_ERROR_CHECK_ALLOC(name->path); *out = name; return 0; @@ -267,7 +267,7 @@ static int possible_tag_dup(struct possible_tag **out, struct possible_tag *in) int error; tag = git__malloc(sizeof(struct possible_tag)); - GITERR_CHECK_ALLOC(tag); + GIT_ERROR_CHECK_ALLOC(tag); memcpy(tag, in, sizeof(struct possible_tag)); tag->name = NULL; @@ -335,14 +335,14 @@ static int display_name(git_buf *buf, git_repository *repo, struct commit_name * { if (n->prio == 2 && !n->tag) { 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; } } if (n->tag && !n->name_checked) { 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; } @@ -425,7 +425,7 @@ static int describe_not_found(const git_oid *oid, const char *message_format) { char oid_str[GIT_OID_HEXSZ + 1]; 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; } @@ -504,7 +504,7 @@ static int describe( unannotated_cnt++; } else if (match_cnt < data->opts->max_candidates_tags) { 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) goto cleanup; @@ -667,7 +667,7 @@ int git_describe_commit( assert(committish); 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.repo = git_object_owner(committish); @@ -675,14 +675,14 @@ int git_describe_commit( if ((error = normalize_options(&normalized, opts)) < 0) return error; - GITERR_CHECK_VERSION( + GIT_ERROR_CHECK_VERSION( &normalized, GIT_DESCRIBE_OPTIONS_VERSION, "git_describe_options"); data.opts = &normalized; data.names = git_oidmap_alloc(); - GITERR_CHECK_ALLOC(data.names); + GIT_ERROR_CHECK_ALLOC(data.names); /** TODO: contains to be implemented */ @@ -695,7 +695,7 @@ int git_describe_commit( goto cleanup; 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."); error = -1; goto cleanup; @@ -786,14 +786,14 @@ int git_describe_format(git_buf *out, const git_describe_result *result, const g 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); git_buf_sanitize(out); 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" "'abbreviated_size'"); return -1; diff --git a/src/diff.c b/src/diff.c index c93e36b39..5abb4d183 100644 --- a/src/diff.c +++ b/src/diff.c @@ -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) { 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->oid_calculations = diff->perf.oid_calculations; return 0; @@ -251,7 +251,7 @@ int git_diff_format_email( assert(out && diff && opts); assert(opts->summary && opts->id && opts->author); - GITERR_CHECK_VERSION(opts, + GIT_ERROR_CHECK_VERSION(opts, GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION, "git_format_email_options"); @@ -260,14 +260,14 @@ int git_diff_format_email( if (!ignore_marker) { if (opts->patch_no > opts->total_patches) { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "patch %"PRIuZ" out of range. max %"PRIuZ, opts->patch_no, opts->total_patches); return -1; } 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); return -1; } @@ -280,14 +280,14 @@ int git_diff_format_email( size_t offset = 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; goto on_error; } - GITERR_CHECK_ALLOC_ADD(&allocsize, offset, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, offset, 1); summary = git__calloc(allocsize, sizeof(char)); - GITERR_CHECK_ALLOC(summary); + GIT_ERROR_CHECK_ALLOC(summary); strncpy(summary, opts->summary, offset); } @@ -466,7 +466,7 @@ static int line_cb( case GIT_DIFF_LINE_CONTEXT: break; default: - giterr_set(GITERR_PATCH, "invalid line origin for patch"); + git_error_set(GIT_ERROR_PATCH, "invalid line origin for patch"); return -1; } @@ -493,7 +493,7 @@ int git_diff_patchid(git_oid *out, git_diff *diff, git_diff_patchid_options *opt struct patch_id_args args; int error; - GITERR_CHECK_VERSION( + GIT_ERROR_CHECK_VERSION( opts, GIT_DIFF_PATCHID_OPTIONS_VERSION, "git_diff_patchid_options"); memset(&args, 0, sizeof(args)); diff --git a/src/diff_driver.c b/src/diff_driver.c index 31bb5a9af..05246dfa3 100644 --- a/src/diff_driver.c +++ b/src/diff_driver.c @@ -149,7 +149,7 @@ static git_diff_driver_registry *git_repository_driver_registry( } 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; } @@ -162,11 +162,11 @@ static int diff_driver_alloc( namelen = strlen(name), alloclen; - GITERR_CHECK_ALLOC_ADD(&alloclen, driverlen, namelen); - GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, driverlen, namelen); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); driver = git__calloc(1, alloclen); - GITERR_CHECK_ALLOC(driver); + GIT_ERROR_CHECK_ALLOC(driver); memcpy(driver->name, name, namelen); @@ -211,7 +211,7 @@ static int git_diff_driver_builtin( (error = p_regcomp( &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; } @@ -256,7 +256,7 @@ static int git_diff_driver_load( /* if you can't read config for repo, just use default driver */ if (git_repository_config_snapshot(&cfg, repo) < 0) { - giterr_clear(); + git_error_clear(); goto done; } @@ -287,7 +287,7 @@ static int git_diff_driver_load( cfg, name.ptr, NULL, diff_driver_xfuncname, drv)) < 0) { if (error != GIT_ENOTFOUND) 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..")); @@ -296,7 +296,7 @@ static int git_diff_driver_load( cfg, name.ptr, NULL, diff_driver_funcname, drv)) < 0) { if (error != GIT_ENOTFOUND) 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 */ @@ -315,7 +315,7 @@ static int git_diff_driver_load( found_driver = true; else { /* 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; } @@ -379,7 +379,7 @@ int git_diff_driver_lookup( else if ((error = git_diff_driver_load(out, repo, values[0])) < 0) { if (error == GIT_ENOTFOUND) { error = 0; - giterr_clear(); + git_error_clear(); } } diff --git a/src/diff_file.c b/src/diff_file.c index b4ccec832..ae1016d9a 100644 --- a/src/diff_file.c +++ b/src/diff_file.c @@ -188,7 +188,7 @@ static int diff_file_content_commit_to_str( if ((error = git_submodule_lookup(&sm, fc->repo, fc->file->path)) < 0) { /* GIT_EEXISTS means a "submodule" that has not been git added */ if (error == GIT_EEXISTS) { - giterr_clear(); + git_error_clear(); error = 0; } return error; @@ -303,13 +303,13 @@ static int diff_file_content_load_workdir_symlink( alloc_len = (ssize_t)(fc->file->size * 2) + 1; 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; read_len = p_readlink(git_buf_cstr(path), fc->map.data, alloc_len); 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; } @@ -352,7 +352,7 @@ static int diff_file_content_load_workdir_file( } /* 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))) { diff --git a/src/diff_generate.c b/src/diff_generate.c index ffe6d80e1..acc6c341b 100644 --- a/src/diff_generate.c +++ b/src/diff_generate.c @@ -81,7 +81,7 @@ static int diff_insert_delta( if (error > 0) /* positive value means to skip this delta */ return 0; 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( return 0; 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 */ assert(status != GIT_DELTA_MODIFIED); @@ -220,7 +220,7 @@ static int diff_delta__from_two( } delta = diff_delta__alloc(diff, status, canonical_path); - GITERR_CHECK_ALLOC(delta); + GIT_ERROR_CHECK_ALLOC(delta); delta->nfiles = 2; if (!git_index_entry_is_conflict(old_entry)) { @@ -517,7 +517,7 @@ static int diff_generated_apply_options( if (entry && git_submodule_parse_ignore( &diff->base.opts.ignore_submodules, entry->value) < 0) - giterr_clear(); + git_error_clear(); git_config_entry_free(entry); } @@ -622,13 +622,13 @@ int git_diff__oid_for_entry( /* if submodule lookup failed probably just in an intermediate * state where some init hasn't happened, so ignore the error */ - giterr_clear(); + git_error_clear(); } } else if (S_ISLNK(mode)) { error = git_odb__hashlink(out, full_path.ptr); diff->base.perf.oid_calculations++; } 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); error = -1; } else if (!(error = git_filter_list_load(&fl, @@ -700,7 +700,7 @@ static int maybe_modified_submodule( /* GIT_EEXISTS means dir with .git in it was found - ignore it */ if (error == GIT_EEXISTS) { - giterr_clear(); + git_error_clear(); error = 0; } return error; @@ -1060,7 +1060,7 @@ static int handle_unmatched_new_item( /* if directory is empty, can't advance into it, so skip it */ if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = iterator_advance(&info->nitem, info->new_iter); } @@ -1082,7 +1082,7 @@ static int handle_unmatched_new_item( else if (nitem->mode == GIT_FILEMODE_COMMIT) { /* ignore things that are not actual submodules */ if (git_submodule_lookup(NULL, info->repo, nitem->path) != 0) { - giterr_clear(); + git_error_clear(); delta_type = GIT_DELTA_IGNORED; /* if this contains a tracked item, treat as normal TREE */ @@ -1091,7 +1091,7 @@ static int handle_unmatched_new_item( if (error != GIT_ENOTFOUND) return error; - giterr_clear(); + git_error_clear(); return iterator_advance(&info->nitem, info->new_iter); } } @@ -1192,7 +1192,7 @@ int git_diff__from_iterators( *out = NULL; diff = diff_generated_alloc(repo, old_iter, new_iter); - GITERR_CHECK_ALLOC(diff); + GIT_ERROR_CHECK_ALLOC(diff); info.repo = repo; info.old_iter = old_iter; @@ -1269,7 +1269,7 @@ cleanup: b_opts.flags = FLAGS_SECOND; \ b_opts.start = 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)) { \ a_opts.pathlist.strings = opts->pathspec.strings; \ a_opts.pathlist.count = opts->pathspec.count; \ @@ -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 */ if (!error && git_index_read(*index, false) < 0) - giterr_clear(); + git_error_clear(); return error; } @@ -1552,7 +1552,7 @@ int git_diff__paired_foreach( } if ((error = cb(h2i, i2w, payload)) != 0) { - giterr_set_after_callback(error); + git_error_set_after_callback(error); break; } } @@ -1591,7 +1591,7 @@ int git_diff__commit( char commit_oidstr[GIT_OID_HEXSZ + 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))); goto on_error; } diff --git a/src/diff_parse.c b/src/diff_parse.c index 59fd8612a..b4c76a3eb 100644 --- a/src/diff_parse.c +++ b/src/diff_parse.c @@ -78,10 +78,10 @@ int git_diff_from_buffer( *out = NULL; diff = diff_parsed_alloc(); - GITERR_CHECK_ALLOC(diff); + GIT_ERROR_CHECK_ALLOC(diff); 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) { if ((error = git_patch_parse(&patch, ctx)) < 0) @@ -92,7 +92,7 @@ int git_diff_from_buffer( } if (error == GIT_ENOTFOUND && git_vector_length(&diff->patches) > 0) { - giterr_clear(); + git_error_clear(); error = 0; } diff --git a/src/diff_print.c b/src/diff_print.c index 090b4e86b..8705615a0 100644 --- a/src/diff_print.c +++ b/src/diff_print.c @@ -224,7 +224,7 @@ static int diff_print_one_raw( delta->new_file.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)", id_abbrev, pi->id_strlen); return -1; @@ -275,7 +275,7 @@ static int diff_print_oid_range( if (delta->old_file.mode && 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)", delta->old_file.id_abbrev, id_strlen); return -1; @@ -283,7 +283,7 @@ static int diff_print_oid_range( if ((delta->new_file.mode && 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)", delta->new_file.id_abbrev, id_strlen); return -1; @@ -343,7 +343,7 @@ int diff_delta_format_similarity_header( int error = 0; 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; goto done; } @@ -540,7 +540,7 @@ static int diff_print_patch_file_binary( binary->old_file.datalen, binary->old_file.inflatedlen)) < 0) { if (error == GIT_EBUFS) { - giterr_clear(); + git_error_clear(); git_buf_truncate(pi->buf, pre_binary_size); return diff_print_patch_file_binary_noshow( @@ -683,7 +683,7 @@ int git_diff_print( print_file = diff_print_one_name_status; break; 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; } @@ -693,7 +693,7 @@ int git_diff_print( diff, print_file, print_binary, print_hunk, print_line, &pi); 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); @@ -711,7 +711,7 @@ int git_diff_print_callback__to_buf( GIT_UNUSED(delta); GIT_UNUSED(hunk); if (!output) { - giterr_set(GITERR_INVALID, "buffer pointer must be provided"); + git_error_set(GIT_ERROR_INVALID, "buffer pointer must be provided"); return -1; } @@ -773,7 +773,7 @@ int git_patch_print( &pi); 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); diff --git a/src/diff_stats.c b/src/diff_stats.c index 3af591443..9cd800651 100644 --- a/src/diff_stats.c +++ b/src/diff_stats.c @@ -184,7 +184,7 @@ int git_diff_get_stats( assert(out && diff); stats = git__calloc(1, sizeof(git_diff_stats)); - GITERR_CHECK_ALLOC(stats); + GIT_ERROR_CHECK_ALLOC(stats); deltas = git_diff_num_deltas(diff); diff --git a/src/diff_tform.c b/src/diff_tform.c index 3a8924d0b..00ce1cbf6 100644 --- a/src/diff_tform.c +++ b/src/diff_tform.c @@ -131,7 +131,7 @@ int git_diff__merge( if (ignore_case != ((from->opts.flags & GIT_DIFF_IGNORE_CASE) != 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"); return -1; } @@ -251,7 +251,7 @@ static int normalize_find_opts( git_config *cfg = NULL; 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 && git_repository_config__weakptr(&cfg, diff->repo) < 0) @@ -332,7 +332,7 @@ static int normalize_find_opts( /* assign the internal metric with whitespace flag as payload */ if (!opts->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->buffer_signature = git_diff_find_similar__hashsig_for_buf; @@ -357,7 +357,7 @@ static int insert_delete_side_of_split( { /* make new record for DELETED side of split */ 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->nfiles = 1; @@ -502,7 +502,7 @@ static int similarity_sig( if (error < 0) { /* if lookup fails, just skip this item in similarity calc */ - giterr_clear(); + git_error_clear(); } else { size_t sz; @@ -831,9 +831,9 @@ int git_diff_find_similar( if ((opts.flags & GIT_DIFF_FIND_ALL) == 0) 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 *)); - GITERR_CHECK_ALLOC(sigcache); + GIT_ERROR_CHECK_ALLOC(sigcache); /* Label rename sources and targets * @@ -856,13 +856,13 @@ int git_diff_find_similar( goto cleanup; 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)); - GITERR_CHECK_ALLOC(tgt2src); + GIT_ERROR_CHECK_ALLOC(tgt2src); if (FLAG_SET(&opts, GIT_DIFF_FIND_COPIES)) { tgt2src_copy = git__calloc(num_deltas, sizeof(diff_find_match)); - GITERR_CHECK_ALLOC(tgt2src_copy); + GIT_ERROR_CHECK_ALLOC(tgt2src_copy); } /* diff --git a/src/diff_xdiff.c b/src/diff_xdiff.c index 6907e52e1..c4668fa2f 100644 --- a/src/diff_xdiff.c +++ b/src/diff_xdiff.c @@ -52,7 +52,7 @@ static int git_xdiff_parse_hunk(git_diff_hunk *hunk, const char *header) return 0; fail: - giterr_set(GITERR_INVALID, "malformed hunk header from xdiff"); + git_error_set(GIT_ERROR_INVALID, "malformed hunk header from xdiff"); return -1; } @@ -101,7 +101,7 @@ static int diff_update_lines( info->new_lineno += (int)line->num_lines; break; 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); return -1; } @@ -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 || 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; } diff --git a/src/errors.c b/src/errors.c index 1ee4fffb0..03097ddcd 100644 --- a/src/errors.c +++ b/src/errors.c @@ -17,7 +17,7 @@ static git_error g_git_oom_error = { "Out of memory", - GITERR_NOMEMORY + GIT_ERROR_NOMEMORY }; static void set_error_from_buffer(int error_class) @@ -49,13 +49,13 @@ void git_error_set_oom(void) 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; #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 - 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_clear(buf); @@ -64,11 +64,11 @@ void giterr_set(int error_class, const char *string, ...) git_buf_vprintf(buf, string, arglist); va_end(arglist); - if (error_class == GITERR_OS) + if (error_class == GIT_ERROR_OS) git_buf_PUTS(buf, ": "); } - if (error_class == GITERR_OS) { + if (error_class == GIT_ERROR_OS) { #ifdef GIT_WIN32 char * win32_error = git_win32_get_error_message(win32_error_code); if (win32_error) { @@ -105,14 +105,14 @@ void git_error_set_str(int error_class, const char *string) 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]; assert(error_code); 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) return GIT_ENOTFOUND; @@ -138,7 +138,7 @@ const git_error *git_error_last(void) 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_buf *error_buf = &GIT_GLOBAL->error_buf; @@ -160,19 +160,19 @@ int giterr_state_capture(git_error_state *state, int error_code) state->error_msg.message = git_buf_detach(error_buf); } - giterr_clear(); + git_error_clear(); return error_code; } -int giterr_state_restore(git_error_state *state) +int git_error_state_restore(git_error_state *state) { int ret = 0; - giterr_clear(); + git_error_clear(); if (state && state->error_msg.message) { if (state->oom) - giterr_set_oom(); + git_error_set_oom(); else set_error(state->error_msg.klass, state->error_msg.message); @@ -183,7 +183,7 @@ int giterr_state_restore(git_error_state *state) return ret; } -void giterr_state_free(git_error_state *state) +void git_error_state_free(git_error_state *state) { if (!state) return; @@ -194,7 +194,7 @@ void giterr_state_free(git_error_state *state) memset(state, 0, sizeof(git_error_state)); } -int giterr_system_last(void) +int git_error_system_last(void) { #ifdef GIT_WIN32 return GetLastError(); @@ -203,7 +203,7 @@ int giterr_system_last(void) #endif } -void giterr_system_set(int code) +void git_error_system_set(int code) { #ifdef GIT_WIN32 SetLastError(code); diff --git a/src/fetch.c b/src/fetch.c index d68df8843..d29341b94 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -113,7 +113,7 @@ int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts) remote->need_pack = 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; } diff --git a/src/fetchhead.c b/src/fetchhead.c index e71021624..bdded029a 100644 --- a/src/fetchhead.c +++ b/src/fetchhead.c @@ -50,7 +50,7 @@ int git_fetchhead_ref_create( *out = NULL; 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)); @@ -148,7 +148,7 @@ static int fetchhead_ref_parse( *remote_url = NULL; if (!*line) { - giterr_set(GITERR_FETCHHEAD, + git_error_set(GIT_ERROR_FETCHHEAD, "empty line in FETCH_HEAD line %"PRIuZ, line_num); return -1; } @@ -162,16 +162,16 @@ static int fetchhead_ref_parse( } 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); return -1; } 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"; - 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); return -1; } @@ -179,7 +179,7 @@ static int fetchhead_ref_parse( /* Parse new data from newer git clients */ if (*line) { 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); return -1; } @@ -189,13 +189,13 @@ static int fetchhead_ref_parse( else if (strcmp(is_merge_str, "not-for-merge") == 0) *is_merge = 0; else { - giterr_set(GITERR_FETCHHEAD, + git_error_set(GIT_ERROR_FETCHHEAD, "invalid for-merge entry in FETCH_HEAD line %"PRIuZ, line_num); return -1; } if ((desc = line) == NULL) { - giterr_set(GITERR_FETCHHEAD, + git_error_set(GIT_ERROR_FETCHHEAD, "invalid description in FETCH_HEAD line %"PRIuZ, line_num); return -1; } @@ -212,7 +212,7 @@ static int fetchhead_ref_parse( if (name) { if ((desc = strstr(name, "' ")) == NULL || git__prefixcmp(desc, "' of ") != 0) { - giterr_set(GITERR_FETCHHEAD, + git_error_set(GIT_ERROR_FETCHHEAD, "invalid description in FETCH_HEAD line %"PRIuZ, line_num); return -1; } @@ -271,13 +271,13 @@ int git_repository_fetchhead_foreach(git_repository *repo, error = cb(ref_name, remote_url, &oid, is_merge, payload); if (error) { - giterr_set_after_callback(error); + git_error_set_after_callback(error); goto done; } } 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; goto done; } diff --git a/src/filebuf.c b/src/filebuf.c index 401910c44..8a70bcd66 100644 --- a/src/filebuf.c +++ b/src/filebuf.c @@ -24,15 +24,15 @@ static int verify_last_error(git_filebuf *file) { switch (file->last_error) { 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; case BUFERR_MEM: - giterr_set_oom(); + git_error_set_oom(); return -1; case BUFERR_ZLIB: - giterr_set(GITERR_ZLIB, + git_error_set(GIT_ERROR_ZLIB, "Buffer error when writing out ZLib data"); return -1; @@ -47,8 +47,8 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode) if (flags & GIT_FILEBUF_FORCE) p_unlink(file->path_lock); else { - giterr_clear(); /* actual OS error code just confuses */ - giterr_set(GITERR_OS, + git_error_clear(); /* actual OS error code just confuses */ + git_error_set(GIT_ERROR_OS, "failed to lock file '%s' for writing", file->path_lock); return GIT_ELOCKED; } @@ -75,7 +75,7 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode) source = p_open(file->path_original, O_RDONLY); if (source < 0) { - giterr_set(GITERR_OS, + git_error_set(GIT_ERROR_OS, "failed to open file '%s' for reading", file->path_original); return -1; @@ -91,10 +91,10 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode) p_close(source); 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; } 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; } } @@ -218,7 +218,7 @@ static int resolve_symlink(git_buf *out, const char *path) } 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; goto cleanup; } @@ -230,13 +230,13 @@ static int resolve_symlink(git_buf *out, const char *path) ret = p_readlink(curpath.ptr, target.ptr, GIT_PATH_MAX); 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; goto cleanup; } 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; goto cleanup; } @@ -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; cleanup: @@ -303,7 +303,7 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo /* Allocate the main cache buffer */ if (!file->do_not_buffer) { 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 */ @@ -320,13 +320,13 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo if (compression != 0) { /* Initialize the ZLib stream */ 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; } /* Allocate the Zlib cache buffer */ file->z_buf = git__malloc(file->buf_size); - GITERR_CHECK_ALLOC(file->z_buf); + GIT_ERROR_CHECK_ALLOC(file->z_buf); /* Never 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 /* No original path */ file->path_original = NULL; file->path_lock = git_buf_detach(&tmp_path); - GITERR_CHECK_ALLOC(file->path_lock); + GIT_ERROR_CHECK_ALLOC(file->path_lock); } else { 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 file->path_original = git_buf_detach(&resolved_path); /* 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); - 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 + path_len, GIT_FILELOCK_EXTENSION, GIT_FILELOCK_EXTLENGTH); 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; goto cleanup; } @@ -411,7 +411,7 @@ int git_filebuf_commit_at(git_filebuf *file, const char *path) { git__free(file->path_original); file->path_original = git__strdup(path); - GITERR_CHECK_ALLOC(file->path_original); + GIT_ERROR_CHECK_ALLOC(file->path_original); return git_filebuf_commit(file); } @@ -430,19 +430,19 @@ int git_filebuf_commit(git_filebuf *file) file->fd_is_open = false; 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; } 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; } file->fd = -1; 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; } @@ -583,7 +583,7 @@ int git_filebuf_stats(time_t *mtime, size_t *size, git_filebuf *file) res = p_stat(file->path_original, &st); 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); return res; } diff --git a/src/fileops.c b/src/fileops.c index b1a9f032a..988ea0f08 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -35,13 +35,13 @@ int git_futils_mktmp(git_buf *path_out, const char *filename, mode_t mode) return -1; if ((fd = p_mkstemp(path_out->ptr)) < 0) { - giterr_set(GITERR_OS, + git_error_set(GIT_ERROR_OS, "failed to create temporary file '%s'", path_out->ptr); return -1; } if (p_chmod(path_out->ptr, (mode & ~mask))) { - giterr_set(GITERR_OS, + git_error_set(GIT_ERROR_OS, "failed to set permissions on file '%s'", path_out->ptr); return -1; } @@ -58,7 +58,7 @@ int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode fd = p_creat(path, mode); if (fd < 0) { - giterr_set(GITERR_OS, "failed to create file '%s'", path); + git_error_set(GIT_ERROR_OS, "failed to create file '%s'", path); return -1; } @@ -72,7 +72,7 @@ int git_futils_creat_locked(const char *path, const mode_t mode) if (fd < 0) { int error = errno; - giterr_set(GITERR_OS, "failed to create locked file '%s'", path); + git_error_set(GIT_ERROR_OS, "failed to create locked file '%s'", path); switch (error) { case EEXIST: return GIT_ELOCKED; @@ -117,7 +117,7 @@ git_off_t git_futils_filesize(git_file fd) struct stat sb; if (p_fstat(fd, &sb)) { - giterr_set(GITERR_OS, "failed to stat file descriptor"); + git_error_set(GIT_ERROR_OS, "failed to stat file descriptor"); return -1; } @@ -146,11 +146,11 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len) git_buf_clear(buf); if (!git__is_ssizet(len)) { - giterr_set(GITERR_INVALID, "read too large"); + git_error_set(GIT_ERROR_INVALID, "read too large"); return -1; } - GITERR_CHECK_ALLOC_ADD(&alloc_len, len, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, len, 1); if (git_buf_grow(buf, alloc_len) < 0) return -1; @@ -158,7 +158,7 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len) read_size = p_read(fd, buf->ptr, len); if (read_size != (ssize_t)len) { - giterr_set(GITERR_OS, "failed to read descriptor"); + git_error_set(GIT_ERROR_OS, "failed to read descriptor"); git_buf_dispose(buf); return -1; } @@ -188,12 +188,12 @@ int git_futils_readbuffer_updated( if (S_ISDIR(st.st_mode)) { - giterr_set(GITERR_INVALID, "requested file is a directory"); + git_error_set(GIT_ERROR_INVALID, "requested file is a directory"); return GIT_ENOTFOUND; } if (!git__is_sizet(st.st_size+1)) { - giterr_set(GITERR_OS, "invalid regular file stat for '%s'", path); + git_error_set(GIT_ERROR_OS, "invalid regular file stat for '%s'", path); return -1; } @@ -261,24 +261,24 @@ int git_futils_writebuffer( mode = GIT_FILEMODE_BLOB; if ((fd = p_open(path, flags, mode)) < 0) { - giterr_set(GITERR_OS, "could not open '%s' for writing", path); + git_error_set(GIT_ERROR_OS, "could not open '%s' for writing", path); return fd; } if ((error = p_write(fd, git_buf_cstr(buf), git_buf_len(buf))) < 0) { - giterr_set(GITERR_OS, "could not write to '%s'", path); + git_error_set(GIT_ERROR_OS, "could not write to '%s'", path); (void)p_close(fd); return error; } if (do_fsync && (error = p_fsync(fd)) < 0) { - giterr_set(GITERR_OS, "could not fsync '%s'", path); + git_error_set(GIT_ERROR_OS, "could not fsync '%s'", path); p_close(fd); return error; } if ((error = p_close(fd)) < 0) { - giterr_set(GITERR_OS, "error while closing '%s'", path); + git_error_set(GIT_ERROR_OS, "error while closing '%s'", path); return error; } @@ -294,7 +294,7 @@ int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmod return -1; if (p_rename(from, to) < 0) { - giterr_set(GITERR_OS, "failed to rename '%s' to '%s'", from, to); + git_error_set(GIT_ERROR_OS, "failed to rename '%s' to '%s'", from, to); return -1; } @@ -321,7 +321,7 @@ int git_futils_mmap_ro_file(git_map *out, const char *path) } if (!git__is_sizet(len)) { - giterr_set(GITERR_OS, "file `%s` too large to mmap", path); + git_error_set(GIT_ERROR_OS, "file `%s` too large to mmap", path); result = -1; goto out; } @@ -346,7 +346,7 @@ GIT_INLINE(int) mkdir_validate_dir( { /* with exclusive create, existing dir is an error */ if ((flags & GIT_MKDIR_EXCL) != 0) { - giterr_set(GITERR_FILESYSTEM, + git_error_set(GIT_ERROR_FILESYSTEM, "failed to make directory '%s': directory exists", path); return GIT_EEXISTS; } @@ -354,7 +354,7 @@ GIT_INLINE(int) mkdir_validate_dir( if ((S_ISREG(st->st_mode) && (flags & GIT_MKDIR_REMOVE_FILES)) || (S_ISLNK(st->st_mode) && (flags & GIT_MKDIR_REMOVE_SYMLINKS))) { if (p_unlink(path) < 0) { - giterr_set(GITERR_OS, "failed to remove %s '%s'", + git_error_set(GIT_ERROR_OS, "failed to remove %s '%s'", S_ISLNK(st->st_mode) ? "symlink" : "file", path); return GIT_EEXISTS; } @@ -362,7 +362,7 @@ GIT_INLINE(int) mkdir_validate_dir( opts->perfdata.mkdir_calls++; if (p_mkdir(path, mode) < 0) { - giterr_set(GITERR_OS, "failed to make directory '%s'", path); + git_error_set(GIT_ERROR_OS, "failed to make directory '%s'", path); return GIT_EEXISTS; } } @@ -372,13 +372,13 @@ GIT_INLINE(int) mkdir_validate_dir( opts->perfdata.stat_calls++; if (p_stat(path, st) < 0) { - giterr_set(GITERR_OS, "failed to make directory '%s'", path); + git_error_set(GIT_ERROR_OS, "failed to make directory '%s'", path); return GIT_EEXISTS; } } else if (!S_ISDIR(st->st_mode)) { - giterr_set(GITERR_FILESYSTEM, + git_error_set(GIT_ERROR_FILESYSTEM, "failed to make directory '%s': directory exists", path); return GIT_EEXISTS; } @@ -400,7 +400,7 @@ GIT_INLINE(int) mkdir_validate_mode( opts->perfdata.chmod_calls++; if (p_chmod(path, mode) < 0) { - giterr_set(GITERR_OS, "failed to set permissions on '%s'", path); + git_error_set(GIT_ERROR_OS, "failed to set permissions on '%s'", path); return -1; } } @@ -415,7 +415,7 @@ GIT_INLINE(int) mkdir_canonicalize( ssize_t root_len; if (path->size == 0) { - giterr_set(GITERR_OS, "attempt to create empty path"); + git_error_set(GIT_ERROR_OS, "attempt to create empty path"); return -1; } @@ -475,7 +475,7 @@ int git_futils_mkdir( if (error == 0) { break; } else if (errno != ENOENT) { - giterr_set(GITERR_OS, "failed to stat '%s'", parent_path.ptr); + git_error_set(GIT_ERROR_OS, "failed to stat '%s'", parent_path.ptr); goto done; } @@ -602,18 +602,18 @@ int git_futils_mkdir_relative( retry_lstat: if (p_lstat(make_path.ptr, &st) < 0) { if (mkdir_attempted || errno != ENOENT) { - giterr_set(GITERR_OS, "cannot access component in path '%s'", make_path.ptr); + git_error_set(GIT_ERROR_OS, "cannot access component in path '%s'", make_path.ptr); error = -1; goto done; } - giterr_clear(); + git_error_clear(); opts->perfdata.mkdir_calls++; mkdir_attempted = true; if (p_mkdir(make_path.ptr, mode) < 0) { if (errno == EEXIST) goto retry_lstat; - giterr_set(GITERR_OS, "failed to make directory '%s'", make_path.ptr); + git_error_set(GIT_ERROR_OS, "failed to make directory '%s'", make_path.ptr); error = -1; goto done; } @@ -632,11 +632,11 @@ retry_lstat: char *cache_path; size_t alloc_size; - GITERR_CHECK_ALLOC_ADD(&alloc_size, make_path.size, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, make_path.size, 1); if (!git__is_uint32(alloc_size)) return -1; cache_path = git_pool_malloc(opts->pool, (uint32_t)alloc_size); - GITERR_CHECK_ALLOC(cache_path); + GIT_ERROR_CHECK_ALLOC(cache_path); memcpy(cache_path, make_path.ptr, make_path.size + 1); @@ -654,7 +654,7 @@ retry_lstat: opts->perfdata.stat_calls++; if (p_stat(make_path.ptr, &st) < 0 || !S_ISDIR(st.st_mode)) { - giterr_set(GITERR_OS, "path is not a directory '%s'", + git_error_set(GIT_ERROR_OS, "path is not a directory '%s'", make_path.ptr); error = GIT_ENOTFOUND; } @@ -677,10 +677,10 @@ typedef struct { static int futils__error_cannot_rmdir(const char *path, const char *filemsg) { if (filemsg) - giterr_set(GITERR_OS, "could not remove directory '%s': %s", + git_error_set(GIT_ERROR_OS, "could not remove directory '%s': %s", path, filemsg); else - giterr_set(GITERR_OS, "could not remove directory '%s'", path); + git_error_set(GIT_ERROR_OS, "could not remove directory '%s'", path); return -1; } @@ -818,7 +818,7 @@ int git_futils_rmdir_r( &fullpath, base, futils__rmdir_empty_parent, &data); if (error == GIT_ITEROVER) { - giterr_clear(); + git_error_clear(); error = 0; } @@ -851,12 +851,12 @@ static int cp_by_fd(int ifd, int ofd, bool close_fd_when_done) error = p_write(ofd, buffer, len); if (len < 0) { - giterr_set(GITERR_OS, "read error while copying file"); + git_error_set(GIT_ERROR_OS, "read error while copying file"); error = (int)len; } if (error < 0) - giterr_set(GITERR_OS, "write error while copying file"); + git_error_set(GIT_ERROR_OS, "write error while copying file"); if (close_fd_when_done) { p_close(ifd); @@ -901,20 +901,20 @@ static int cp_link(const char *from, const char *to, size_t link_size) char *link_data; size_t alloc_size; - GITERR_CHECK_ALLOC_ADD(&alloc_size, link_size, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, link_size, 1); link_data = git__malloc(alloc_size); - GITERR_CHECK_ALLOC(link_data); + GIT_ERROR_CHECK_ALLOC(link_data); read_len = p_readlink(from, link_data, link_size); if (read_len != (ssize_t)link_size) { - giterr_set(GITERR_OS, "failed to read symlink data for '%s'", from); + git_error_set(GIT_ERROR_OS, "failed to read symlink data for '%s'", from); error = -1; } else { link_data[read_len] = '\0'; if (p_symlink(link_data, to) < 0) { - giterr_set(GITERR_OS, "could not symlink '%s' as '%s'", + git_error_set(GIT_ERROR_OS, "could not symlink '%s' as '%s'", link_data, to); error = -1; } @@ -977,7 +977,7 @@ static int _cp_r_callback(void *ref, git_buf *from) else if (error != GIT_ENOTFOUND) return error; else { - giterr_clear(); + git_error_clear(); error = 0; } @@ -1010,7 +1010,7 @@ static int _cp_r_callback(void *ref, git_buf *from) return 0; if (p_unlink(info->to.ptr) < 0) { - giterr_set(GITERR_OS, "cannot overwrite existing file '%s'", + git_error_set(GIT_ERROR_OS, "cannot overwrite existing file '%s'", info->to.ptr); return GIT_EEXISTS; } @@ -1030,7 +1030,7 @@ static int _cp_r_callback(void *ref, git_buf *from) /* make symlink or regular file */ if (info->flags & GIT_CPDIR_LINK_FILES) { if ((error = p_link(from->ptr, info->to.ptr)) < 0) - giterr_set(GITERR_OS, "failed to link '%s'", from->ptr); + git_error_set(GIT_ERROR_OS, "failed to link '%s'", from->ptr); } else if (S_ISLNK(from_st.st_mode)) { error = cp_link(from->ptr, info->to.ptr, (size_t)from_st.st_size); } else { @@ -1155,12 +1155,12 @@ int git_futils_fsync_dir(const char *path) int fd, error = -1; if ((fd = p_open(path, O_RDONLY)) < 0) { - giterr_set(GITERR_OS, "failed to open directory '%s' for fsync", path); + git_error_set(GIT_ERROR_OS, "failed to open directory '%s' for fsync", path); return -1; } if ((error = p_fsync(fd)) < 0) - giterr_set(GITERR_OS, "failed to fsync directory '%s'", path); + git_error_set(GIT_ERROR_OS, "failed to fsync directory '%s'", path); p_close(fd); return error; diff --git a/src/fileops.h b/src/fileops.h index 2844ece21..85131f834 100644 --- a/src/fileops.h +++ b/src/fileops.h @@ -340,7 +340,7 @@ typedef struct { * 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, * 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. * * @param stamp File stamp to be checked diff --git a/src/filter.c b/src/filter.c index 90cc55198..4c9c7416b 100644 --- a/src/filter.c +++ b/src/filter.c @@ -157,15 +157,15 @@ static int filter_registry_insert( if (filter_def_scan_attrs(&attrs, &nattr, &nmatch, filter->attributes) < 0) return -1; - GITERR_CHECK_ALLOC_MULTIPLY(&alloc_len, nattr, 2); - GITERR_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_MULTIPLY(&alloc_len, nattr, 2); + GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloc_len, alloc_len, sizeof(char *)); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, sizeof(git_filter_def)); fdef = git__calloc(1, alloc_len); - GITERR_CHECK_ALLOC(fdef); + GIT_ERROR_CHECK_ALLOC(fdef); fdef->filter_name = git__strdup(name); - GITERR_CHECK_ALLOC(fdef->filter_name); + GIT_ERROR_CHECK_ALLOC(fdef->filter_name); fdef->filter = filter; fdef->priority = priority; @@ -269,13 +269,13 @@ int git_filter_register( assert(name && filter); 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; } if (!filter_registry_find(NULL, name)) { - giterr_set( - GITERR_FILTER, "attempt to reregister existing filter '%s'", name); + git_error_set( + GIT_ERROR_FILTER, "attempt to reregister existing filter '%s'", name); error = GIT_EEXISTS; goto done; } @@ -297,17 +297,17 @@ int git_filter_unregister(const char *name) /* cannot unregister default filters */ 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; } 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; } 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; goto done; } @@ -348,7 +348,7 @@ git_filter *git_filter_lookup(const char *name) git_filter *filter = NULL; 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; } @@ -404,11 +404,11 @@ static int filter_list_new( git_filter_list *fl = NULL; size_t pathlen = src->path ? strlen(src->path) : 0, alloclen; - GITERR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_filter_list), pathlen); - GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_filter_list), pathlen); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); fl = git__calloc(1, alloclen); - GITERR_CHECK_ALLOC(fl); + GIT_ERROR_CHECK_ALLOC(fl); if (src->path) memcpy(fl->path, src->path, pathlen); @@ -431,14 +431,14 @@ static int filter_list_check_attributes( int error; size_t i; 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( 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 (error == GIT_ENOTFOUND && !fdef->nmatches) { - giterr_clear(); + git_error_clear(); git__free((void *)strs); return 0; } @@ -499,7 +499,7 @@ int git_filter_list__load_ext( git_filter_def *fdef; 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; } @@ -551,7 +551,7 @@ int git_filter_list__load_ext( } fe = git_array_alloc(fl->filters); - GITERR_CHECK_ALLOC(fe); + GIT_ERROR_CHECK_ALLOC(fe); fe->filter = fdef->filter; fe->filter_name = fdef->filter_name; @@ -634,7 +634,7 @@ int git_filter_list_push( assert(fl && filter); 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; } @@ -646,7 +646,7 @@ int git_filter_list_push( git_rwlock_rdunlock(&filter_registry.lock); 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; } @@ -654,7 +654,7 @@ int git_filter_list_push( return error; fe = git_array_alloc(fl->filters); - GITERR_CHECK_ALLOC(fe); + GIT_ERROR_CHECK_ALLOC(fe); fe->filter = filter; fe->payload = payload; @@ -759,7 +759,7 @@ static int buf_from_blob(git_buf *out, git_blob *blob) git_off_t rawsize = git_blob_rawsize(blob); 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; } @@ -829,9 +829,9 @@ static int proxy_stream_close(git_writestream *s) } else { /* close stream before erroring out taking care * 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); - giterr_state_restore(&error_state); + git_error_state_restore(&error_state); return error; } @@ -861,7 +861,7 @@ static int proxy_stream_init( git_writestream *target) { 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.close = proxy_stream_close; diff --git a/src/hash/hash_collisiondetect.h b/src/hash/hash_collisiondetect.h index 4e4c7da55..743209802 100644 --- a/src/hash/hash_collisiondetect.h +++ b/src/hash/hash_collisiondetect.h @@ -41,7 +41,7 @@ GIT_INLINE(int) git_hash_final(git_oid *out, git_hash_ctx *ctx) { assert(ctx); 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; } diff --git a/src/hash/hash_openssl.h b/src/hash/hash_openssl.h index 9a32cba2a..8dbfd5ad5 100644 --- a/src/hash/hash_openssl.h +++ b/src/hash/hash_openssl.h @@ -29,7 +29,7 @@ GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx) assert(ctx); 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; } @@ -41,7 +41,7 @@ GIT_INLINE(int) git_hash_update(git_hash_ctx *ctx, const void *data, size_t len) assert(ctx); 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; } @@ -53,7 +53,7 @@ GIT_INLINE(int) git_hash_final(git_oid *out, git_hash_ctx *ctx) assert(ctx); 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; } diff --git a/src/hash/hash_win32.c b/src/hash/hash_win32.c index 779802c4b..4b6830358 100644 --- a/src/hash/hash_win32.c +++ b/src/hash/hash_win32.c @@ -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) */ 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; } @@ -35,7 +35,7 @@ GIT_INLINE(int) hash_cng_prov_init(void) StringCchCat(dll_path, MAX_PATH, "\\") < 0 || StringCchCat(dll_path, MAX_PATH, GIT_HASH_CNG_DLL_NAME) < 0 || (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; } @@ -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) { 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; } @@ -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) { 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; } @@ -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); 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; } @@ -86,7 +86,7 @@ GIT_INLINE(void) hash_cng_prov_shutdown(void) GIT_INLINE(int) hash_cryptoapi_prov_init() { 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; } @@ -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)) { 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; } @@ -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; 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; } @@ -178,7 +178,7 @@ GIT_INLINE(int) hash_cryptoapi_final(git_oid *out, git_hash_ctx *ctx) assert(ctx->ctx.cryptoapi.valid); 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; } @@ -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) { 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; } @@ -223,7 +223,7 @@ GIT_INLINE(int) hash_cng_init(git_hash_ctx *ctx) /* 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) { - giterr_set(GITERR_OS, "hash implementation could not be finished"); + git_error_set(GIT_ERROR_OS, "hash implementation could not be finished"); return -1; } @@ -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; 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; } @@ -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) { 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; } diff --git a/src/hashsig.c b/src/hashsig.c index 30d059463..abebd7a54 100644 --- a/src/hashsig.c +++ b/src/hashsig.c @@ -216,7 +216,7 @@ static int hashsig_finalize_hashes(git_hashsig *sig) { if (sig->mins.size < HASHSIG_HEAP_MIN_SIZE && !(sig->opt & GIT_HASHSIG_ALLOW_SMALL_FILES)) { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "file too small for similarity signature calculation"); return GIT_EBUFS; } @@ -249,7 +249,7 @@ int git_hashsig_create( int error; hashsig_in_progress prog; git_hashsig *sig = hashsig_alloc(opts); - GITERR_CHECK_ALLOC(sig); + GIT_ERROR_CHECK_ALLOC(sig); hashsig_in_progress_init(&prog, sig); @@ -276,7 +276,7 @@ int git_hashsig_create_fromfile( int error = 0, fd; hashsig_in_progress prog; git_hashsig *sig = hashsig_alloc(opts); - GITERR_CHECK_ALLOC(sig); + GIT_ERROR_CHECK_ALLOC(sig); if ((fd = git_futils_open_ro(path)) < 0) { git__free(sig); @@ -288,7 +288,7 @@ int git_hashsig_create_fromfile( while (!error) { if ((buflen = p_read(fd, buf, sizeof(buf))) <= 0) { if ((error = (int)buflen) < 0) - giterr_set(GITERR_OS, + git_error_set(GIT_ERROR_OS, "read error on '%s' calculating similarity hashes", path); break; } diff --git a/src/idxmap.c b/src/idxmap.c index edf8fff5a..3a5fc105a 100644 --- a/src/idxmap.c +++ b/src/idxmap.c @@ -35,7 +35,7 @@ __KHASH_IMPL(idxicase, static kh_inline, const git_index_entry *, git_index_entr int git_idxmap_alloc(git_idxmap **map) { if ((*map = kh_init(idx)) == NULL) { - giterr_set_oom(); + git_error_set_oom(); return -1; } @@ -45,7 +45,7 @@ int git_idxmap_alloc(git_idxmap **map) int git_idxmap_icase_alloc(git_idxmap_icase **map) { if ((*map = kh_init(idxicase)) == NULL) { - giterr_set_oom(); + git_error_set_oom(); return -1; } diff --git a/src/ignore.c b/src/ignore.c index e1d5fc9af..c6e4da705 100644 --- a/src/ignore.c +++ b/src/ignore.c @@ -142,7 +142,7 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match goto out; 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; } @@ -171,7 +171,7 @@ static int parse_ignore_file( git_attr_fnmatch *match = NULL; 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 (attrs->entry && @@ -180,7 +180,7 @@ static int parse_ignore_file( context = attrs->entry->path; 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; } @@ -624,7 +624,7 @@ int git_ignore__check_pathspec_for_exact_ignores( break; if (ignored) { - giterr_set(GITERR_INVALID, "pathspec contains ignored file '%s'", + git_error_set(GIT_ERROR_INVALID, "pathspec contains ignored file '%s'", filename); error = GIT_EINVALIDSPEC; break; diff --git a/src/index.c b/src/index.c index e4f0338df..677faea47 100644 --- a/src/index.c +++ b/src/index.c @@ -408,7 +408,7 @@ int git_index_open(git_index **index_out, const char *index_path) assert(index_out); index = git__calloc(1, sizeof(git_index)); - GITERR_CHECK_ALLOC(index); + GIT_ERROR_CHECK_ALLOC(index); git_pool_init(&index->tree_pool, 1); @@ -550,7 +550,7 @@ int git_index_clear(git_index *index) static int create_index_error(int error, const char *msg) { - giterr_set_str(GITERR_INDEX, msg); + git_error_set_str(GIT_ERROR_INDEX, msg); return error; } @@ -616,7 +616,7 @@ static int compare_checksum(git_index *index) if (p_lseek(fd, -20, SEEK_END) < 0) { p_close(fd); - giterr_set(GITERR_OS, "failed to seek to end of file"); + git_error_set(GIT_ERROR_OS, "failed to seek to end of file"); return -1; } @@ -651,8 +651,8 @@ int git_index_read(git_index *index, int force) if ((updated = git_futils_filestamp_check(&stamp, index->index_file_path) < 0) || ((updated = compare_checksum(index)) < 0)) { - giterr_set( - GITERR_INDEX, + git_error_set( + GIT_ERROR_INDEX, "failed to read index: '%s' no longer exists", index->index_file_path); return updated; @@ -685,7 +685,7 @@ int git_index_read(git_index *index, int force) int git_index_read_safely(git_index *index) { if (git_index__enforce_unsaved_safety && index->dirty) { - giterr_set(GITERR_INDEX, + git_error_set(GIT_ERROR_INDEX, "the index has unsaved changes that would be overwritten by this operation"); return GIT_EINDEXDIRTY; } @@ -698,7 +698,7 @@ int git_index__changed_relative_to( { /* attempt to update index (ignoring errors) */ if (git_index_read(index, false) < 0) - giterr_clear(); + git_error_clear(); return !!git_oid_cmp(&index->checksum, checksum); } @@ -781,7 +781,7 @@ int git_index_set_version(git_index *index, unsigned int version) if (version < INDEX_VERSION_NUMBER_LB || version > INDEX_VERSION_NUMBER_UB) { - giterr_set(GITERR_INDEX, "invalid version number"); + git_error_set(GIT_ERROR_INDEX, "invalid version number"); return -1; } @@ -864,7 +864,7 @@ const git_index_entry *git_index_get_bypath( if (git_idxmap_valid_index(index->entries_map, pos)) return git_idxmap_value_at(index->entries_map, pos); - giterr_set(GITERR_INDEX, "index does not contain '%s'", path); + git_error_set(GIT_ERROR_INDEX, "index does not contain '%s'", path); return NULL; } @@ -926,14 +926,14 @@ static int index_entry_create( mode = st->st_mode; if (!git_path_isvalid(repo, path, mode, path_valid_flags)) { - giterr_set(GITERR_INDEX, "invalid path: '%s'", path); + git_error_set(GIT_ERROR_INDEX, "invalid path: '%s'", path); return -1; } - GITERR_CHECK_ALLOC_ADD(&alloclen, sizeof(struct entry_internal), pathlen); - GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(struct entry_internal), pathlen); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); entry = git__calloc(1, alloclen); - GITERR_CHECK_ALLOC(entry); + GIT_ERROR_CHECK_ALLOC(entry); entry->pathlen = pathlen; memcpy(entry->path, path, pathlen); @@ -1030,7 +1030,7 @@ static int index_entry_reuc_init(git_index_reuc_entry **reuc_out, assert(reuc_out && path); *reuc_out = reuc = reuc_entry_alloc(path); - GITERR_CHECK_ALLOC(reuc); + GIT_ERROR_CHECK_ALLOC(reuc); if ((reuc->mode[0] = ancestor_mode) > 0) { assert(ancestor_oid); @@ -1177,7 +1177,7 @@ static int check_file_directory_collision(git_index *index, { if (has_file_name(index, entry, pos, ok_to_replace) < 0 || has_dir_name(index, entry, ok_to_replace) < 0) { - giterr_set(GITERR_INDEX, + git_error_set(GIT_ERROR_INDEX, "'%s' appears as both a file and a directory", entry->path); return -1; } @@ -1259,7 +1259,7 @@ static int index_no_dups(void **old, void *new) { const git_index_entry *entry = new; GIT_UNUSED(old); - giterr_set(GITERR_INDEX, "'%s' appears multiple times at stage %d", + git_error_set(GIT_ERROR_INDEX, "'%s' appears multiple times at stage %d", entry->path, GIT_INDEX_ENTRY_STAGE(entry)); return GIT_EEXISTS; } @@ -1469,7 +1469,7 @@ int git_index_add_frombuffer( "Index is not backed up by an existing repository."); if (!is_file_or_link(source_entry->mode)) { - giterr_set(GITERR_INDEX, "invalid filemode"); + git_error_set(GIT_ERROR_INDEX, "invalid filemode"); return -1; } @@ -1510,7 +1510,7 @@ static int add_repo_as_submodule(git_index_entry **out, git_index *index, const return error; if ((error = p_stat(abspath.ptr, &st)) < 0) { - giterr_set(GITERR_OS, "failed to stat repository dir"); + git_error_set(GIT_ERROR_OS, "failed to stat repository dir"); return -1; } @@ -1554,13 +1554,13 @@ int git_index_add_bypath(git_index *index, const char *path) git_submodule *sm; git_error_state err; - giterr_state_capture(&err, ret); + git_error_state_capture(&err, ret); ret = git_submodule_lookup(&sm, INDEX_OWNER(index), path); if (ret == GIT_ENOTFOUND) - return giterr_state_restore(&err); + return git_error_state_restore(&err); - giterr_state_free(&err); + git_error_state_free(&err); /* * EEXISTS means that there is a repository at that path, but it's not known @@ -1602,7 +1602,7 @@ int git_index_remove_bypath(git_index *index, const char *path) return ret; if (ret == GIT_ENOTFOUND) - giterr_clear(); + git_error_clear(); return 0; } @@ -1656,7 +1656,7 @@ int git_index_add(git_index *index, const git_index_entry *source_entry) assert(index && source_entry && source_entry->path); if (!valid_filemode(source_entry->mode)) { - giterr_set(GITERR_INDEX, "invalid entry mode"); + git_error_set(GIT_ERROR_INDEX, "invalid entry mode"); return -1; } @@ -1680,8 +1680,8 @@ int git_index_remove(git_index *index, const char *path, int stage) DELETE_IN_MAP(index, &remove_key); if (index_find(&position, index, path, 0, stage) < 0) { - giterr_set( - GITERR_INDEX, "index does not contain %s at stage %d", path, stage); + git_error_set( + GIT_ERROR_INDEX, "index does not contain %s at stage %d", path, stage); error = GIT_ENOTFOUND; } else { error = index_remove_entry(index, position); @@ -1753,7 +1753,7 @@ int git_index_find(size_t *at_pos, git_index *index, const char *path) if (git_vector_bsearch2( &pos, &index->entries, index->entries_search_path, path) < 0) { - giterr_set(GITERR_INDEX, "index does not contain %s", path); + git_error_set(GIT_ERROR_INDEX, "index does not contain %s", path); return GIT_ENOTFOUND; } @@ -1795,7 +1795,7 @@ int git_index_conflict_add(git_index *index, /* Validate entries */ for (i = 0; i < 3; i++) { if (entries[i] && !valid_filemode(entries[i]->mode)) { - giterr_set(GITERR_INDEX, "invalid filemode for stage %d entry", + git_error_set(GIT_ERROR_INDEX, "invalid filemode for stage %d entry", i + 1); ret = -1; goto on_error; @@ -1811,7 +1811,7 @@ int git_index_conflict_add(git_index *index, if (ret != GIT_ENOTFOUND) goto on_error; - giterr_clear(); + git_error_clear(); ret = 0; } } @@ -1981,7 +1981,7 @@ int git_index_iterator_new( assert(iterator_out && index); it = git__calloc(1, sizeof(git_index_iterator)); - GITERR_CHECK_ALLOC(it); + GIT_ERROR_CHECK_ALLOC(it); if ((error = git_index_snapshot_new(&it->snap, index)) < 0) { git__free(it); @@ -2025,7 +2025,7 @@ int git_index_conflict_iterator_new( assert(iterator_out && index); it = git__calloc(1, sizeof(git_index_conflict_iterator)); - GITERR_CHECK_ALLOC(it); + GIT_ERROR_CHECK_ALLOC(it); it->index = index; @@ -2111,7 +2111,7 @@ int git_index_name_add(git_index *index, assert((ancestor && ours) || (ancestor && theirs) || (ours && theirs)); conflict_name = git__calloc(1, sizeof(git_index_name_entry)); - GITERR_CHECK_ALLOC(conflict_name); + GIT_ERROR_CHECK_ALLOC(conflict_name); if ((ancestor && !(conflict_name->ancestor = git__strdup(ancestor))) || (ours && !(conflict_name->ours = git__strdup(ours))) || @@ -2251,7 +2251,7 @@ void git_index_reuc_clear(git_index *index) static int index_error_invalid(const char *message) { - giterr_set(GITERR_INDEX, "invalid data in index - %s", message); + git_error_set(GIT_ERROR_INDEX, "invalid data in index - %s", message); return -1; } @@ -2274,7 +2274,7 @@ static int read_reuc(git_index *index, const char *buffer, size_t size) return index_error_invalid("reading reuc entries"); lost = reuc_entry_alloc(buffer); - GITERR_CHECK_ALLOC(lost); + GIT_ERROR_CHECK_ALLOC(lost); size -= len; buffer += len; @@ -2347,7 +2347,7 @@ static int read_conflict_names(git_index *index, const char *buffer, size_t size ptr = NULL; \ else { \ ptr = git__malloc(len); \ - GITERR_CHECK_ALLOC(ptr); \ + GIT_ERROR_CHECK_ALLOC(ptr); \ memcpy(ptr, buffer, len); \ } \ \ @@ -2356,7 +2356,7 @@ static int read_conflict_names(git_index *index, const char *buffer, size_t size while (size) { git_index_name_entry *conflict_name = git__calloc(1, sizeof(git_index_name_entry)); - GITERR_CHECK_ALLOC(conflict_name); + GIT_ERROR_CHECK_ALLOC(conflict_name); read_conflict_name(conflict_name->ancestor); read_conflict_name(conflict_name->ours); @@ -2478,14 +2478,14 @@ static int read_entry( prefix_len = last_len - strip_len; suffix_len = strlen(path_ptr + varint_len); - GITERR_CHECK_ALLOC_ADD(&path_len, prefix_len, suffix_len); - GITERR_CHECK_ALLOC_ADD(&path_len, path_len, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&path_len, prefix_len, suffix_len); + GIT_ERROR_CHECK_ALLOC_ADD(&path_len, path_len, 1); if (path_len > GIT_PATH_MAX) return index_error_invalid("unreasonable path length"); tmp_path = git__malloc(path_len); - GITERR_CHECK_ALLOC(tmp_path); + GIT_ERROR_CHECK_ALLOC(tmp_path); memcpy(tmp_path, last, prefix_len); memcpy(tmp_path + prefix_len, path_ptr + varint_len, suffix_len + 1); @@ -3132,7 +3132,7 @@ int git_index_read_tree(git_index *index, const git_tree *tree) INSERT_IN_MAP_EX(index, entries_map, e, &error); if (error < 0) { - giterr_set(GITERR_INDEX, "failed to insert entry into map"); + git_error_set(GIT_ERROR_INDEX, "failed to insert entry into map"); return error; } } @@ -3257,7 +3257,7 @@ static int git_index_read_iterator( error = git_vector_insert(&remove_entries, remove_entry); if (error < 0) { - giterr_set(GITERR_INDEX, "failed to insert entry"); + git_error_set(GIT_ERROR_INDEX, "failed to insert entry"); goto done; } @@ -3366,7 +3366,7 @@ int git_index_add_all( error = index_apply_to_wd_diff(index, INDEX_ACTION_ADDALL, paths, flags, cb, payload); if (error) - giterr_set_after_callback(error); + git_error_set_after_callback(error); cleanup: git_iterator_free(wditer); @@ -3468,7 +3468,7 @@ static int index_apply_to_wd_diff(git_index *index, int action, const git_strarr git_diff_free(diff); if (error) /* make sure error is set if callback stopped iteration */ - giterr_set_after_callback(error); + git_error_set_after_callback(error); cleanup: git_pathspec__clear(&ps); @@ -3525,7 +3525,7 @@ static int index_apply_to_all( error = git_index_add_bypath(index, path.ptr); if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = git_index_remove_bypath(index, path.ptr); @@ -3538,7 +3538,7 @@ static int index_apply_to_all( i--; /* back up foreach if we removed this */ break; default: - giterr_set(GITERR_INVALID, "unknown index action %d", action); + git_error_set(GIT_ERROR_INVALID, "unknown index action %d", action); error = -1; break; } @@ -3560,7 +3560,7 @@ int git_index_remove_all( index, INDEX_ACTION_REMOVE, pathspec, cb, payload); if (error) /* make sure error is set if callback stopped iteration */ - giterr_set_after_callback(error); + git_error_set_after_callback(error); return error; } @@ -3573,7 +3573,7 @@ int git_index_update_all( { int error = index_apply_to_wd_diff(index, INDEX_ACTION_UPDATE, pathspec, 0, cb, payload); if (error) /* make sure error is set if callback stopped iteration */ - giterr_set_after_callback(error); + git_error_set_after_callback(error); return error; } @@ -3629,7 +3629,7 @@ int git_indexwriter_init( &writer->file, index->index_file_path, GIT_FILEBUF_HASH_CONTENTS, GIT_INDEX_FILE_MODE)) < 0) { if (error == GIT_ELOCKED) - giterr_set(GITERR_INDEX, "the index is locked; this might be due to a concurrent or crashed process"); + git_error_set(GIT_ERROR_INDEX, "the index is locked; this might be due to a concurrent or crashed process"); return error; } @@ -3678,7 +3678,7 @@ int git_indexwriter_commit(git_indexwriter *writer) if ((error = git_futils_filestamp_check( &writer->index->stamp, writer->index->index_file_path)) < 0) { - giterr_set(GITERR_OS, "could not read index timestamp"); + git_error_set(GIT_ERROR_OS, "could not read index timestamp"); return -1; } diff --git a/src/indexer.c b/src/indexer.c index dd9990423..27b763790 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -95,12 +95,12 @@ static int parse_header(struct git_pack_header *hdr, struct git_pack_file *pack) /* Verify we recognize this pack file format. */ if (hdr->hdr_signature != ntohl(PACK_SIGNATURE)) { - giterr_set(GITERR_INDEXER, "wrong pack signature"); + git_error_set(GIT_ERROR_INDEXER, "wrong pack signature"); return -1; } if (!pack_version_ok(hdr->hdr_version)) { - giterr_set(GITERR_INDEXER, "wrong pack version"); + git_error_set(GIT_ERROR_INDEXER, "wrong pack version"); return -1; } @@ -139,7 +139,7 @@ int git_indexer_new( memcpy(&opts, in_opts, sizeof(opts)); idx = git__calloc(1, sizeof(git_indexer)); - GITERR_CHECK_ALLOC(idx); + GIT_ERROR_CHECK_ALLOC(idx); idx->odb = odb; idx->progress_cb = opts.progress_cb; idx->progress_payload = opts.progress_cb_payload; @@ -148,7 +148,7 @@ int git_indexer_new( git_hash_ctx_init(&idx->trailer); git_buf_init(&idx->entry_data, 0); idx->expected_oids = git_oidmap_alloc(); - GITERR_CHECK_ALLOC(idx->expected_oids); + GIT_ERROR_CHECK_ALLOC(idx->expected_oids); idx->do_verify = opts.verify; @@ -204,7 +204,7 @@ static int store_delta(git_indexer *idx) struct delta_info *delta; delta = git__calloc(1, sizeof(struct delta_info)); - GITERR_CHECK_ALLOC(delta); + GIT_ERROR_CHECK_ALLOC(delta); delta->delta_off = idx->entry_start; if (git_vector_insert(&idx->deltas, delta) < 0) @@ -410,10 +410,10 @@ static int store_object(git_indexer *idx) git_off_t entry_start = idx->entry_start; entry = git__calloc(1, sizeof(*entry)); - GITERR_CHECK_ALLOC(entry); + GIT_ERROR_CHECK_ALLOC(entry); pentry = git__calloc(1, sizeof(struct git_pack_entry)); - GITERR_CHECK_ALLOC(pentry); + GIT_ERROR_CHECK_ALLOC(pentry); git_hash_final(&oid, &idx->hash_ctx); entry_size = idx->off - entry_start; @@ -441,12 +441,12 @@ static int store_object(git_indexer *idx) k = git_oidmap_put(idx->pack->idx_cache, &pentry->sha1, &error); if (error == -1) { git__free(pentry); - giterr_set_oom(); + git_error_set_oom(); goto on_error; } if (error == 0) { - giterr_set(GITERR_INDEXER, "duplicate object %s found in pack", git_oid_tostr_s(&pentry->sha1)); + git_error_set(GIT_ERROR_INDEXER, "duplicate object %s found in pack", git_oid_tostr_s(&pentry->sha1)); git__free(pentry); goto on_error; } @@ -496,7 +496,7 @@ static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_ent k = git_oidmap_put(idx->pack->idx_cache, &pentry->sha1, &error); if (error <= 0) { - giterr_set(GITERR_INDEXER, "cannot insert object into pack"); + git_error_set(GIT_ERROR_INDEXER, "cannot insert object into pack"); return -1; } @@ -521,15 +521,15 @@ static int hash_and_save(git_indexer *idx, git_rawobj *obj, git_off_t entry_star struct git_pack_entry *pentry = NULL; entry = git__calloc(1, sizeof(*entry)); - GITERR_CHECK_ALLOC(entry); + GIT_ERROR_CHECK_ALLOC(entry); if (git_odb__hashobj(&oid, obj) < 0) { - giterr_set(GITERR_INDEXER, "failed to hash object"); + git_error_set(GIT_ERROR_INDEXER, "failed to hash object"); goto on_error; } pentry = git__calloc(1, sizeof(struct git_pack_entry)); - GITERR_CHECK_ALLOC(pentry); + GIT_ERROR_CHECK_ALLOC(pentry); git_oid_cpy(&pentry->sha1, &oid); git_oid_cpy(&entry->oid, &oid); @@ -551,7 +551,7 @@ on_error: static int do_progress_callback(git_indexer *idx, git_transfer_progress *stats) { if (idx->progress_cb) - return giterr_set_after_callback_function( + return git_error_set_after_callback_function( idx->progress_cb(stats, idx->progress_payload), "indexer progress"); return 0; @@ -649,7 +649,7 @@ static int append_to_pack(git_indexer *idx, const void *data, size_t size) if (p_lseek(fd, page_start + mmap_alignment - 1, SEEK_SET) < 0 || p_write(idx->pack->mwf.fd, data, 1) < 0) { - giterr_set(GITERR_OS, "cannot extend packfile '%s'", idx->pack->pack_name); + git_error_set(GIT_ERROR_OS, "cannot extend packfile '%s'", idx->pack->pack_name); return -1; } @@ -777,12 +777,12 @@ int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_tran if (idx->nr_objects <= git_indexer__max_objects) { total_objects = (unsigned int)idx->nr_objects; } else { - giterr_set(GITERR_INDEXER, "too many objects"); + git_error_set(GIT_ERROR_INDEXER, "too many objects"); return -1; } idx->pack->idx_cache = git_oidmap_alloc(); - GITERR_CHECK_ALLOC(idx->pack->idx_cache); + GIT_ERROR_CHECK_ALLOC(idx->pack->idx_cache); idx->pack->has_cache = 1; if (git_vector_init(&idx->objects, total_objects, objects_cmp) < 0) @@ -872,7 +872,7 @@ static int inject_object(git_indexer *idx, git_oid *id) entry_start = idx->pack->mwf.size; if (git_odb_read(&obj, idx->odb, id) < 0) { - giterr_set(GITERR_INDEXER, "missing delta bases"); + git_error_set(GIT_ERROR_INDEXER, "missing delta bases"); return -1; } @@ -880,7 +880,7 @@ static int inject_object(git_indexer *idx, git_oid *id) len = git_odb_object_size(obj); entry = git__calloc(1, sizeof(*entry)); - GITERR_CHECK_ALLOC(entry); + GIT_ERROR_CHECK_ALLOC(entry); entry->crc = crc32(0L, Z_NULL, 0); @@ -911,7 +911,7 @@ static int inject_object(git_indexer *idx, git_oid *id) idx->pack->mwf.size += GIT_OID_RAWSZ; pentry = git__calloc(1, sizeof(struct git_pack_entry)); - GITERR_CHECK_ALLOC(pentry); + GIT_ERROR_CHECK_ALLOC(pentry); git_oid_cpy(&pentry->sha1, id); git_oid_cpy(&entry->oid, id); @@ -945,7 +945,7 @@ static int fix_thin_pack(git_indexer *idx, git_transfer_progress *stats) assert(git_vector_length(&idx->deltas) > 0); if (idx->odb == NULL) { - giterr_set(GITERR_INDEXER, "cannot fix a thin pack without an ODB"); + git_error_set(GIT_ERROR_INDEXER, "cannot fix a thin pack without an ODB"); return -1; } @@ -966,14 +966,14 @@ static int fix_thin_pack(git_indexer *idx, git_transfer_progress *stats) } if (!found_ref_delta) { - giterr_set(GITERR_INDEXER, "no REF_DELTA found, cannot inject object"); + git_error_set(GIT_ERROR_INDEXER, "no REF_DELTA found, cannot inject object"); return -1; } /* curpos now points to the base information, which is an OID */ base_info = git_mwindow_open(&idx->pack->mwf, &w, curpos, GIT_OID_RAWSZ, &left); if (base_info == NULL) { - giterr_set(GITERR_INDEXER, "failed to map delta information"); + git_error_set(GIT_ERROR_INDEXER, "failed to map delta information"); return -1; } @@ -1102,17 +1102,17 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats) void *packfile_trailer; if (!idx->parsed_header) { - giterr_set(GITERR_INDEXER, "incomplete pack header"); + git_error_set(GIT_ERROR_INDEXER, "incomplete pack header"); return -1; } /* Test for this before resolve_deltas(), as it plays with idx->off */ if (idx->off + 20 < idx->pack->mwf.size) { - giterr_set(GITERR_INDEXER, "unexpected data at the end of the pack"); + git_error_set(GIT_ERROR_INDEXER, "unexpected data at the end of the pack"); return -1; } if (idx->off + 20 > idx->pack->mwf.size) { - giterr_set(GITERR_INDEXER, "missing trailer at the end of the pack"); + git_error_set(GIT_ERROR_INDEXER, "missing trailer at the end of the pack"); return -1; } @@ -1128,7 +1128,7 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats) git_hash_final(&trailer_hash, &idx->trailer); if (git_oid_cmp(&file_hash, &trailer_hash)) { - giterr_set(GITERR_INDEXER, "packfile trailer mismatch"); + git_error_set(GIT_ERROR_INDEXER, "packfile trailer mismatch"); return -1; } @@ -1139,7 +1139,7 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats) return error; if (stats->indexed_objects != stats->total_objects) { - giterr_set(GITERR_INDEXER, "early EOF"); + git_error_set(GIT_ERROR_INDEXER, "early EOF"); return -1; } @@ -1158,7 +1158,7 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats) * packfile. */ if (git_oidmap_size(idx->expected_oids) > 0) { - giterr_set(GITERR_INDEXER, "packfile is missing %"PRIuZ" objects", + git_error_set(GIT_ERROR_INDEXER, "packfile is missing %"PRIuZ" objects", git_oidmap_size(idx->expected_oids)); return -1; } @@ -1249,18 +1249,18 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats) /* Truncate file to undo rounding up to next page_size in append_to_pack */ if (p_ftruncate(idx->pack->mwf.fd, idx->pack->mwf.size) < 0) { - giterr_set(GITERR_OS, "failed to truncate pack file '%s'", idx->pack->pack_name); + git_error_set(GIT_ERROR_OS, "failed to truncate pack file '%s'", idx->pack->pack_name); return -1; } if (idx->do_fsync && p_fsync(idx->pack->mwf.fd) < 0) { - giterr_set(GITERR_OS, "failed to fsync packfile"); + git_error_set(GIT_ERROR_OS, "failed to fsync packfile"); goto on_error; } /* We need to close the descriptor here so Windows doesn't choke on commit_at */ if (p_close(idx->pack->mwf.fd) < 0) { - giterr_set(GITERR_OS, "failed to close packfile"); + git_error_set(GIT_ERROR_OS, "failed to close packfile"); goto on_error; } diff --git a/src/iterator.c b/src/iterator.c index b12c8ff0a..90bbb813b 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -46,14 +46,14 @@ static int iterator_range_init( { if (start && *start) { iter->start = git__strdup(start); - GITERR_CHECK_ALLOC(iter->start); + GIT_ERROR_CHECK_ALLOC(iter->start); iter->start_len = strlen(iter->start); } if (end && *end) { iter->end = git__strdup(end); - GITERR_CHECK_ALLOC(iter->end); + GIT_ERROR_CHECK_ALLOC(iter->end); iter->end_len = strlen(iter->end); } @@ -146,7 +146,7 @@ static int iterator_init_common( (iter->flags & GIT_ITERATOR_DONT_PRECOMPOSE_UNICODE) == 0) { if (git_repository__cvar(&precompose, repo, GIT_CVAR_PRECOMPOSE) < 0) - giterr_clear(); + git_error_clear(); else if (precompose) iter->flags |= GIT_ITERATOR_PRECOMPOSE_UNICODE; } @@ -403,7 +403,7 @@ int git_iterator_for_nothing( *out = NULL; iter = git__calloc(1, sizeof(empty_iterator)); - GITERR_CHECK_ALLOC(iter); + GIT_ERROR_CHECK_ALLOC(iter); iter->base.type = GIT_ITERATOR_TYPE_EMPTY; iter->base.cb = &callbacks; @@ -541,7 +541,7 @@ static int tree_iterator_frame_init( int error = 0; new_frame = git_array_alloc(iter->frames); - GITERR_CHECK_ALLOC(new_frame); + GIT_ERROR_CHECK_ALLOC(new_frame); memset(new_frame, 0, sizeof(tree_iterator_frame)); @@ -564,7 +564,7 @@ static int tree_iterator_frame_init( git_array_foreach(dup->entries, i, tree_entry) { new_entry = git_pool_malloc(&iter->entry_pool, 1); - GITERR_CHECK_ALLOC(new_entry); + GIT_ERROR_CHECK_ALLOC(new_entry); new_entry->tree_entry = tree_entry; new_entry->parent_path = new_frame->path.ptr; @@ -618,20 +618,20 @@ GIT_INLINE(int) tree_iterator_frame_push_neighbors( break; path = git_array_alloc(parent_frame->similar_paths); - GITERR_CHECK_ALLOC(path); + GIT_ERROR_CHECK_ALLOC(path); memset(path, 0, sizeof(git_buf)); if ((error = tree_iterator_compute_path(path, entry)) < 0) break; - GITERR_CHECK_ALLOC_ADD(&new_size, + GIT_ERROR_CHECK_ALLOC_ADD(&new_size, frame->entries.length, tree->entries.size); git_vector_size_hint(&frame->entries, new_size); git_array_foreach(tree->entries, i, tree_entry) { new_entry = git_pool_malloc(&iter->entry_pool, 1); - GITERR_CHECK_ALLOC(new_entry); + GIT_ERROR_CHECK_ALLOC(new_entry); new_entry->tree_entry = tree_entry; new_entry->parent_path = path->ptr; @@ -947,7 +947,7 @@ int git_iterator_for_tree( return git_iterator_for_nothing(out, options); iter = git__calloc(1, sizeof(tree_iterator)); - GITERR_CHECK_ALLOC(iter); + GIT_ERROR_CHECK_ALLOC(iter); iter->base.type = GIT_ITERATOR_TYPE_TREE; iter->base.cb = &callbacks; @@ -1143,7 +1143,7 @@ static void filesystem_iterator_frame_push_ignores( if (git_ignore__lookup(&new_frame->is_ignored, &iter->ignores, path, GIT_DIR_FLAG_TRUE) < 0) { - giterr_clear(); + git_error_clear(); new_frame->is_ignored = GIT_IGNORE_NOTFOUND; } @@ -1299,12 +1299,12 @@ static int filesystem_iterator_entry_init( /* Make sure to append two bytes, one for the path's null * termination, one for a possible trailing '/' for folders. */ - GITERR_CHECK_ALLOC_ADD(&entry_size, + GIT_ERROR_CHECK_ALLOC_ADD(&entry_size, sizeof(filesystem_iterator_entry), path_len); - GITERR_CHECK_ALLOC_ADD(&entry_size, entry_size, 2); + GIT_ERROR_CHECK_ALLOC_ADD(&entry_size, entry_size, 2); entry = git_pool_malloc(&frame->entry_pool, entry_size); - GITERR_CHECK_ALLOC(entry); + GIT_ERROR_CHECK_ALLOC(entry); entry->path_len = path_len; entry->match = pathlist_match; @@ -1340,13 +1340,13 @@ static int filesystem_iterator_frame_push( int error; if (iter->frames.size == FILESYSTEM_MAX_DEPTH) { - giterr_set(GITERR_REPOSITORY, + git_error_set(GIT_ERROR_REPOSITORY, "directory nesting too deep (%"PRIuZ")", iter->frames.size); return -1; } new_frame = git_array_alloc(iter->frames); - GITERR_CHECK_ALLOC(new_frame); + GIT_ERROR_CHECK_ALLOC(new_frame); memset(new_frame, 0, sizeof(filesystem_iterator_frame)); @@ -1695,7 +1695,7 @@ static void filesystem_iterator_update_ignored(filesystem_iterator *iter) if (git_ignore__lookup(&iter->current_is_ignored, &iter->ignores, iter->entry.path, dir_flag) < 0) { - giterr_clear(); + git_error_clear(); iter->current_is_ignored = GIT_IGNORE_NOTFOUND; } @@ -1904,7 +1904,7 @@ static int iterator_for_filesystem( return git_iterator_for_nothing(out, options); iter = git__calloc(1, sizeof(filesystem_iterator)); - GITERR_CHECK_ALLOC(iter); + GIT_ERROR_CHECK_ALLOC(iter); iter->base.type = type; iter->base.cb = &callbacks; @@ -1912,7 +1912,7 @@ static int iterator_for_filesystem( root_len = strlen(root); iter->root = git__malloc(root_len+2); - GITERR_CHECK_ALLOC(iter->root); + GIT_ERROR_CHECK_ALLOC(iter->root); memcpy(iter->root, root, root_len); @@ -2234,7 +2234,7 @@ int git_iterator_for_index( return git_iterator_for_nothing(out, options); iter = git__calloc(1, sizeof(index_iterator)); - GITERR_CHECK_ALLOC(iter); + GIT_ERROR_CHECK_ALLOC(iter); iter->base.type = GIT_ITERATOR_TYPE_INDEX; iter->base.cb = &callbacks; @@ -2334,8 +2334,8 @@ int git_iterator_walk( iterator_item = git__calloc(cnt, sizeof(git_index_entry *)); cur_items = git__calloc(cnt, sizeof(git_index_entry *)); - GITERR_CHECK_ALLOC(iterator_item); - GITERR_CHECK_ALLOC(cur_items); + GIT_ERROR_CHECK_ALLOC(iterator_item); + GIT_ERROR_CHECK_ALLOC(cur_items); /* Set up the iterators */ for (i = 0; i < cnt; i++) { diff --git a/src/mailmap.c b/src/mailmap.c index ba4d4cec9..409cdbd3c 100644 --- a/src/mailmap.c +++ b/src/mailmap.c @@ -149,7 +149,7 @@ int git_mailmap_new(git_mailmap **out) { int error; git_mailmap *mm = git__calloc(1, sizeof(git_mailmap)); - GITERR_CHECK_ALLOC(mm); + GIT_ERROR_CHECK_ALLOC(mm); error = git_vector_init(&mm->entries, 0, mailmap_entry_cmp); if (error < 0) { @@ -183,24 +183,24 @@ static int mailmap_add_entry_unterminated( { int error; git_mailmap_entry *entry = git__calloc(1, sizeof(git_mailmap_entry)); - GITERR_CHECK_ALLOC(entry); + GIT_ERROR_CHECK_ALLOC(entry); assert(mm && replace_email && *replace_email); if (real_name_size > 0) { entry->real_name = git__substrdup(real_name, real_name_size); - GITERR_CHECK_ALLOC(entry->real_name); + GIT_ERROR_CHECK_ALLOC(entry->real_name); } if (real_email_size > 0) { entry->real_email = git__substrdup(real_email, real_email_size); - GITERR_CHECK_ALLOC(entry->real_email); + GIT_ERROR_CHECK_ALLOC(entry->real_email); } if (replace_name_size > 0) { entry->replace_name = git__substrdup(replace_name, replace_name_size); - GITERR_CHECK_ALLOC(entry->replace_name); + GIT_ERROR_CHECK_ALLOC(entry->replace_name); } entry->replace_email = git__substrdup(replace_email, replace_email_size); - GITERR_CHECK_ALLOC(entry->replace_email); + GIT_ERROR_CHECK_ALLOC(entry->replace_email); error = git_vector_insert_sorted(&mm->entries, entry, mailmap_entry_replace); if (error == GIT_EEXISTS) diff --git a/src/merge.c b/src/merge.c index 754b08900..14b76fa2e 100644 --- a/src/merge.c +++ b/src/merge.c @@ -80,7 +80,7 @@ int merge_bases_many(git_commit_list **out, git_revwalk **walk_out, git_reposito unsigned int i; if (length < 2) { - giterr_set(GITERR_INVALID, "at least two commits are required to find an ancestor"); + git_error_set(GIT_ERROR_INVALID, "at least two commits are required to find an ancestor"); return -1; } @@ -106,7 +106,7 @@ int merge_bases_many(git_commit_list **out, git_revwalk **walk_out, git_reposito goto on_error; if (!result) { - giterr_set(GITERR_MERGE, "no merge base found"); + git_error_set(GIT_ERROR_MERGE, "no merge base found"); error = GIT_ENOTFOUND; goto on_error; } @@ -186,7 +186,7 @@ int git_merge_base_octopus(git_oid *out, git_repository *repo, size_t length, co assert(out && repo && input_array); if (length < 2) { - giterr_set(GITERR_INVALID, "at least two commits are required to find an ancestor"); + git_error_set(GIT_ERROR_INVALID, "at least two commits are required to find an ancestor"); return -1; } @@ -232,7 +232,7 @@ static int merge_bases(git_commit_list **out, git_revwalk **walk_out, git_reposi if (!result) { git_revwalk_free(walk); - giterr_set(GITERR_MERGE, "no merge base found"); + git_error_set(GIT_ERROR_MERGE, "no merge base found"); return GIT_ENOTFOUND; } @@ -426,9 +426,9 @@ static int remove_redundant(git_revwalk *walk, git_vector *commits) int error = 0; redundant = git__calloc(commits->length, 1); - GITERR_CHECK_ALLOC(redundant); + GIT_ERROR_CHECK_ALLOC(redundant); filled_index = git__calloc((commits->length - 1), sizeof(unsigned int)); - GITERR_CHECK_ALLOC(filled_index); + GIT_ERROR_CHECK_ALLOC(filled_index); for (i = 0; i < commits->length; ++i) { if ((error = git_commit_list_parse(walk, commits->contents[i])) < 0) @@ -576,7 +576,7 @@ int git_repository_mergehead_foreach( while ((line = git__strsep(&buffer, "\n")) != NULL) { if (strlen(line) != GIT_OID_HEXSZ) { - giterr_set(GITERR_INVALID, "unable to parse OID - invalid length"); + git_error_set(GIT_ERROR_INVALID, "unable to parse OID - invalid length"); error = -1; goto cleanup; } @@ -585,7 +585,7 @@ int git_repository_mergehead_foreach( goto cleanup; if ((error = cb(&oid, payload)) != 0) { - giterr_set_after_callback(error); + git_error_set_after_callback(error); goto cleanup; } @@ -593,7 +593,7 @@ int git_repository_mergehead_foreach( } if (*buffer) { - giterr_set(GITERR_MERGE, "no EOL at line %"PRIuZ, line_num); + git_error_set(GIT_ERROR_MERGE, "no EOL at line %"PRIuZ, line_num); error = -1; goto cleanup; } @@ -863,14 +863,14 @@ static int merge_conflict_invoke_driver( goto done; result = git_pool_mallocz(&diff_list->pool, sizeof(git_index_entry)); - GITERR_CHECK_ALLOC(result); + GIT_ERROR_CHECK_ALLOC(result); git_oid_cpy(&result->id, &oid); result->mode = mode; result->file_size = buf.size; result->path = git_pool_strdup(&diff_list->pool, path); - GITERR_CHECK_ALLOC(result->path); + GIT_ERROR_CHECK_ALLOC(result->path); *out = result; @@ -1113,7 +1113,7 @@ static int deletes_by_oid_enqueue(git_oidmap *map, git_pool* pool, const git_oid pos = git_oidmap_lookup_index(map, id); if (!git_oidmap_valid_index(map, pos)) { queue = git_pool_malloc(pool, sizeof(deletes_by_oid_queue)); - GITERR_CHECK_ALLOC(queue); + GIT_ERROR_CHECK_ALLOC(queue); git_array_init(queue->arr); queue->next_pos = 0; @@ -1125,7 +1125,7 @@ static int deletes_by_oid_enqueue(git_oidmap *map, git_pool* pool, const git_oid } else { queue = git_oidmap_value_at(map, pos); array_entry = git_array_alloc(queue->arr); - GITERR_CHECK_ALLOC(array_entry); + GIT_ERROR_CHECK_ALLOC(array_entry); *array_entry = idx; } @@ -1510,11 +1510,11 @@ int git_merge_diff_list__find_renames( similarity_ours = git__calloc(diff_list->conflicts.length, sizeof(struct merge_diff_similarity)); - GITERR_CHECK_ALLOC(similarity_ours); + GIT_ERROR_CHECK_ALLOC(similarity_ours); similarity_theirs = git__calloc(diff_list->conflicts.length, sizeof(struct merge_diff_similarity)); - GITERR_CHECK_ALLOC(similarity_theirs); + GIT_ERROR_CHECK_ALLOC(similarity_theirs); /* Calculate similarity between items that were deleted from the ancestor * and added in the other branch. @@ -1523,9 +1523,9 @@ int git_merge_diff_list__find_renames( goto done; if (opts->rename_threshold < 100 && diff_list->conflicts.length <= opts->target_limit) { - GITERR_CHECK_ALLOC_MULTIPLY(&cache_size, diff_list->conflicts.length, 3); + GIT_ERROR_CHECK_ALLOC_MULTIPLY(&cache_size, diff_list->conflicts.length, 3); cache = git__calloc(cache_size, sizeof(void *)); - GITERR_CHECK_ALLOC(cache); + GIT_ERROR_CHECK_ALLOC(cache); merge_diff_list_count_candidates(diff_list, &src_count, &tgt_count); @@ -1739,7 +1739,7 @@ static int merge_diff_list_insert_unmodified( git_index_entry *entry; entry = git_pool_malloc(&diff_list->pool, sizeof(git_index_entry)); - GITERR_CHECK_ALLOC(entry); + GIT_ERROR_CHECK_ALLOC(entry); if ((error = index_entry_dup_pool(entry, &diff_list->pool, tree_items[0])) >= 0) error = git_vector_insert(&diff_list->staged, entry); @@ -1846,13 +1846,13 @@ static int merge_normalize_opts( if (given && given->default_driver) { opts->default_driver = git__strdup(given->default_driver); - GITERR_CHECK_ALLOC(opts->default_driver); + GIT_ERROR_CHECK_ALLOC(opts->default_driver); } else { error = git_config_get_entry(&entry, cfg, "merge.default"); if (error == 0) { opts->default_driver = git__strdup(entry->value); - GITERR_CHECK_ALLOC(opts->default_driver); + GIT_ERROR_CHECK_ALLOC(opts->default_driver); } else if (error == GIT_ENOTFOUND) { error = 0; } else { @@ -1873,7 +1873,7 @@ static int merge_normalize_opts( /* assign the internal metric with whitespace flag as payload */ if (!opts->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->buffer_signature = git_diff_find_similar__hashsig_for_buf; @@ -2060,7 +2060,7 @@ int git_merge__iterators( *out = NULL; - GITERR_CHECK_VERSION( + GIT_ERROR_CHECK_VERSION( given_opts, GIT_MERGE_OPTIONS_VERSION, "git_merge_options"); if ((error = merge_normalize_opts(repo, &opts, given_opts)) < 0) @@ -2079,7 +2079,7 @@ int git_merge__iterators( } diff_list = git_merge_diff_list__alloc(repo); - GITERR_CHECK_ALLOC(diff_list); + GIT_ERROR_CHECK_ALLOC(diff_list); ancestor_iter = iterator_given_or_empty(&empty_ancestor, ancestor_iter); our_iter = iterator_given_or_empty(&empty_ours, our_iter); @@ -2102,7 +2102,7 @@ int git_merge__iterators( if (!resolved) { if ((opts.flags & GIT_MERGE_FAIL_ON_CONFLICT)) { - giterr_set(GITERR_MERGE, "merge conflicts exist"); + git_error_set(GIT_ERROR_MERGE, "merge conflicts exist"); error = GIT_EMERGECONFLICT; goto done; } @@ -2199,13 +2199,13 @@ GIT_INLINE(int) insert_head_ids( if (annotated_commit->type == GIT_ANNOTATED_COMMIT_REAL) { id = git_array_alloc(*ids); - GITERR_CHECK_ALLOC(id); + GIT_ERROR_CHECK_ALLOC(id); git_oid_cpy(id, git_commit_id(annotated_commit->commit)); } else { for (i = 0; i < annotated_commit->parents.size; i++) { id = git_array_alloc(*ids); - GITERR_CHECK_ALLOC(id); + GIT_ERROR_CHECK_ALLOC(id); git_oid_cpy(id, &annotated_commit->parents.ptr[i]); } @@ -2240,7 +2240,7 @@ static int create_virtual_base( return -1; result = git__calloc(1, sizeof(git_annotated_commit)); - GITERR_CHECK_ALLOC(result); + GIT_ERROR_CHECK_ALLOC(result); result->type = GIT_ANNOTATED_COMMIT_VIRTUAL; result->index = index; @@ -2368,7 +2368,7 @@ static int merge_annotated_commits( if (error != GIT_ENOTFOUND) goto done; - giterr_clear(); + git_error_clear(); } if ((error = iterator_for_annotated_commit(&base_iter, base)) < 0 || @@ -2678,7 +2678,7 @@ static int write_merge_msg( assert(repo && heads); entries = git__calloc(heads_len, sizeof(struct merge_msg_entry)); - GITERR_CHECK_ALLOC(entries); + GIT_ERROR_CHECK_ALLOC(entries); if (git_vector_init(&matching, heads_len, NULL) < 0) { git__free(entries); @@ -2812,9 +2812,9 @@ static int merge_ancestor_head( assert(repo && our_head && their_heads); - GITERR_CHECK_ALLOC_ADD(&alloc_len, their_heads_len, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, their_heads_len, 1); oids = git__calloc(alloc_len, sizeof(git_oid)); - GITERR_CHECK_ALLOC(oids); + GIT_ERROR_CHECK_ALLOC(oids); git_oid_cpy(&oids[0], git_commit_id(our_head->commit)); @@ -3038,7 +3038,7 @@ int git_merge__check_result(git_repository *repo, git_index *index_new) goto done; if ((conflicts = index_conflicts + wd_conflicts) > 0) { - giterr_set(GITERR_MERGE, "%" PRIuZ " uncommitted change%s would be overwritten by merge", + git_error_set(GIT_ERROR_MERGE, "%" PRIuZ " uncommitted change%s would be overwritten by merge", conflicts, (conflicts != 1) ? "s" : ""); error = GIT_ECONFLICT; } @@ -3130,7 +3130,7 @@ static int merge_heads( if (error != GIT_ENOTFOUND) goto done; - giterr_clear(); + git_error_clear(); error = 0; } @@ -3159,7 +3159,7 @@ static int merge_preference(git_merge_preference_t *out, git_repository *repo) if ((error = git_config_get_string(&value, config, "merge.ff")) < 0) { if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = 0; } @@ -3194,7 +3194,7 @@ int git_merge_analysis_for_ref( assert(analysis_out && preference_out && repo && their_heads && their_heads_len > 0); if (their_heads_len != 1) { - giterr_set(GITERR_MERGE, "can only merge a single branch"); + git_error_set(GIT_ERROR_MERGE, "can only merge a single branch"); error = -1; goto done; } @@ -3247,7 +3247,7 @@ int git_merge_analysis( int error = 0; if ((error = git_reference_lookup(&head_ref, repo, GIT_HEAD_FILE)) < 0) { - giterr_set(GITERR_MERGE, "failed to lookup HEAD reference"); + git_error_set(GIT_ERROR_MERGE, "failed to lookup HEAD reference"); return error; } @@ -3276,7 +3276,7 @@ int git_merge( assert(repo && their_heads && their_heads_len > 0); if (their_heads_len != 1) { - giterr_set(GITERR_MERGE, "can only merge a single branch"); + git_error_set(GIT_ERROR_MERGE, "can only merge a single branch"); return -1; } diff --git a/src/merge_driver.c b/src/merge_driver.c index ea4bd2787..8b7e3559a 100644 --- a/src/merge_driver.c +++ b/src/merge_driver.c @@ -181,7 +181,7 @@ static int merge_driver_registry_insert( git_merge_driver_entry *entry; entry = git__calloc(1, sizeof(git_merge_driver_entry) + strlen(name) + 1); - GITERR_CHECK_ALLOC(entry); + GIT_ERROR_CHECK_ALLOC(entry); strcpy(entry->name, name); entry->driver = driver; @@ -265,12 +265,12 @@ int git_merge_driver_register(const char *name, git_merge_driver *driver) assert(name && driver); if (git_rwlock_wrlock(&merge_driver_registry.lock) < 0) { - giterr_set(GITERR_OS, "failed to lock merge driver registry"); + git_error_set(GIT_ERROR_OS, "failed to lock merge driver registry"); return -1; } if (!merge_driver_registry_find(NULL, name)) { - giterr_set(GITERR_MERGE, "attempt to reregister existing driver '%s'", + git_error_set(GIT_ERROR_MERGE, "attempt to reregister existing driver '%s'", name); error = GIT_EEXISTS; goto done; @@ -290,12 +290,12 @@ int git_merge_driver_unregister(const char *name) int error = 0; if (git_rwlock_wrlock(&merge_driver_registry.lock) < 0) { - giterr_set(GITERR_OS, "failed to lock merge driver registry"); + git_error_set(GIT_ERROR_OS, "failed to lock merge driver registry"); return -1; } if ((entry = merge_driver_registry_lookup(&pos, name)) == NULL) { - giterr_set(GITERR_MERGE, "cannot find merge driver '%s' to unregister", + git_error_set(GIT_ERROR_MERGE, "cannot find merge driver '%s' to unregister", name); error = GIT_ENOTFOUND; goto done; @@ -332,7 +332,7 @@ git_merge_driver *git_merge_driver_lookup(const char *name) return &git_merge_driver__binary; if (git_rwlock_rdlock(&merge_driver_registry.lock) < 0) { - giterr_set(GITERR_OS, "failed to lock merge driver registry"); + git_error_set(GIT_ERROR_OS, "failed to lock merge driver registry"); return NULL; } @@ -341,7 +341,7 @@ git_merge_driver *git_merge_driver_lookup(const char *name) git_rwlock_rdunlock(&merge_driver_registry.lock); if (entry == NULL) { - giterr_set(GITERR_MERGE, "cannot use an unregistered filter"); + git_error_set(GIT_ERROR_MERGE, "cannot use an unregistered filter"); return NULL; } diff --git a/src/merge_file.c b/src/merge_file.c index a36c1986c..0647a5df6 100644 --- a/src/merge_file.c +++ b/src/merge_file.c @@ -130,7 +130,7 @@ static int merge_file__xdiff( if ((xdl_result = xdl_merge(&ancestor_mmfile, &our_mmfile, &their_mmfile, &xmparam, &mmbuffer)) < 0) { - giterr_set(GITERR_MERGE, "failed to merge files"); + git_error_set(GIT_ERROR_MERGE, "failed to merge files"); error = -1; goto done; } diff --git a/src/mwindow.c b/src/mwindow.c index 16508c190..ffbee7d14 100644 --- a/src/mwindow.c +++ b/src/mwindow.c @@ -58,7 +58,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path) return error; if (git_mutex_lock(&git__mwindow_mutex) < 0) { - giterr_set(GITERR_OS, "failed to lock mwindow mutex"); + git_error_set(GIT_ERROR_OS, "failed to lock mwindow mutex"); return -1; } @@ -122,7 +122,7 @@ void git_mwindow_put_pack(struct git_pack_file *pack) void git_mwindow_free_all(git_mwindow_file *mwf) { if (git_mutex_lock(&git__mwindow_mutex)) { - giterr_set(GITERR_THREAD, "unable to lock mwindow mutex"); + git_error_set(GIT_ERROR_THREAD, "unable to lock mwindow mutex"); return; } @@ -229,7 +229,7 @@ static int git_mwindow_close_lru(git_mwindow_file *mwf) } if (!lru_w) { - giterr_set(GITERR_OS, "failed to close memory window; couldn't find LRU"); + git_error_set(GIT_ERROR_OS, "failed to close memory window; couldn't find LRU"); return -1; } @@ -324,7 +324,7 @@ unsigned char *git_mwindow_open( git_mwindow *w = *cursor; if (git_mutex_lock(&git__mwindow_mutex)) { - giterr_set(GITERR_THREAD, "unable to lock mwindow mutex"); + git_error_set(GIT_ERROR_THREAD, "unable to lock mwindow mutex"); return NULL; } @@ -376,7 +376,7 @@ int git_mwindow_file_register(git_mwindow_file *mwf) int ret; if (git_mutex_lock(&git__mwindow_mutex)) { - giterr_set(GITERR_THREAD, "unable to lock mwindow mutex"); + git_error_set(GIT_ERROR_THREAD, "unable to lock mwindow mutex"); return -1; } @@ -416,7 +416,7 @@ void git_mwindow_close(git_mwindow **window) git_mwindow *w = *window; if (w) { if (git_mutex_lock(&git__mwindow_mutex)) { - giterr_set(GITERR_THREAD, "unable to lock mwindow mutex"); + git_error_set(GIT_ERROR_THREAD, "unable to lock mwindow mutex"); return; } diff --git a/src/netops.c b/src/netops.c index 272d0ccd8..ecbc2aebe 100644 --- a/src/netops.c +++ b/src/netops.c @@ -153,7 +153,7 @@ int gitno_connection_data_from_url( default_port = default_port_http; if (data->use_ssl) { - giterr_set(GITERR_NET, "redirect from HTTPS to HTTP is not allowed"); + git_error_set(GIT_ERROR_NET, "redirect from HTTPS to HTTP is not allowed"); goto cleanup; } } else if (!git__prefixcmp(url, prefix_https)) { @@ -164,7 +164,7 @@ int gitno_connection_data_from_url( default_port = gitno__default_port(data); if (!default_port) { - giterr_set(GITERR_NET, "unrecognized URL prefix"); + git_error_set(GIT_ERROR_NET, "unrecognized URL prefix"); goto cleanup; } @@ -196,7 +196,7 @@ int gitno_connection_data_from_url( /* Check for errors in the resulting data */ if (original_host && url[0] != '/' && strcmp(original_host, data->host)) { - giterr_set(GITERR_NET, "cross host redirect not allowed"); + git_error_set(GIT_ERROR_NET, "cross host redirect not allowed"); error = -1; } } @@ -234,7 +234,7 @@ int gitno_extract_url_parts( int error = 0; if (http_parser_parse_url(url, strlen(url), false, &u)) { - giterr_set(GITERR_NET, "malformed URL '%s'", url); + git_error_set(GIT_ERROR_NET, "malformed URL '%s'", url); error = GIT_EINVALIDSPEC; goto done; } @@ -263,7 +263,7 @@ int gitno_extract_url_parts( size_t url_path_len = u.field_data[UF_PATH].len; git_buf_decode_percent(&path, url_path, url_path_len); } else if (path_out) { - giterr_set(GITERR_NET, "invalid url, missing path"); + git_error_set(GIT_ERROR_NET, "invalid url, missing path"); error = GIT_EINVALIDSPEC; goto done; } diff --git a/src/notes.c b/src/notes.c index ebab0cdd3..2931353d3 100644 --- a/src/notes.c +++ b/src/notes.c @@ -15,7 +15,7 @@ static int note_error_notfound(void) { - giterr_set(GITERR_INVALID, "note could not be found"); + git_error_set(GIT_ERROR_INVALID, "note could not be found"); return GIT_ENOTFOUND; } @@ -226,7 +226,7 @@ static int remove_note_in_tree_enotfound_cb( GIT_UNUSED(note_oid); GIT_UNUSED(fanout); - giterr_set(GITERR_REPOSITORY, "object '%s' has no note", annotated_object_sha); + git_error_set(GIT_ERROR_REPOSITORY, "object '%s' has no note", annotated_object_sha); return current_error; } @@ -244,7 +244,7 @@ static int insert_note_in_tree_eexists_cb(git_tree **out, GIT_UNUSED(note_oid); GIT_UNUSED(fanout); - giterr_set(GITERR_REPOSITORY, "note for '%s' exists already", annotated_object_sha); + git_error_set(GIT_ERROR_REPOSITORY, "note for '%s' exists already", annotated_object_sha); return current_error; } @@ -321,7 +321,7 @@ static int note_new( git_note *note = NULL; note = git__malloc(sizeof(git_note)); - GITERR_CHECK_ALLOC(note); + GIT_ERROR_CHECK_ALLOC(note); git_oid_cpy(¬e->id, note_oid); @@ -330,7 +330,7 @@ static int note_new( return -1; note->message = git__strndup(git_blob_rawcontent(blob), git_blob_rawsize(blob)); - GITERR_CHECK_ALLOC(note->message); + GIT_ERROR_CHECK_ALLOC(note->message); *out = note; return 0; @@ -417,7 +417,7 @@ static int normalize_namespace(char **out, git_repository *repo, const char *not { if (notes_ref) { *out = git__strdup(notes_ref); - GITERR_CHECK_ALLOC(*out); + GIT_ERROR_CHECK_ALLOC(*out); return 0; } @@ -729,7 +729,7 @@ int git_note_foreach( while (!(error = git_note_next(¬e_id, &annotated_id, iter))) { if ((error = note_cb(¬e_id, &annotated_id, payload)) != 0) { - giterr_set_after_callback(error); + git_error_set_after_callback(error); break; } } diff --git a/src/object.c b/src/object.c index ce432648a..15f2722c7 100644 --- a/src/object.c +++ b/src/object.c @@ -71,18 +71,18 @@ int git_object__from_raw( /* Validate type match */ if (type != GIT_OBJECT_BLOB && type != GIT_OBJECT_TREE && type != GIT_OBJECT_COMMIT && type != GIT_OBJECT_TAG) { - giterr_set(GITERR_INVALID, "the requested type is invalid"); + git_error_set(GIT_ERROR_INVALID, "the requested type is invalid"); return GIT_ENOTFOUND; } if ((object_size = git_object__size(type)) == 0) { - giterr_set(GITERR_INVALID, "the requested type is invalid"); + git_error_set(GIT_ERROR_INVALID, "the requested type is invalid"); return GIT_ENOTFOUND; } /* Allocate and initialize base object */ object = git__calloc(1, object_size); - GITERR_CHECK_ALLOC(object); + GIT_ERROR_CHECK_ALLOC(object); object->cached.flags = GIT_CACHE_STORE_PARSED; object->cached.type = type; git_odb_hash(&object->cached.oid, data, size, type); @@ -118,19 +118,19 @@ int git_object__from_odb_object( /* Validate type match */ if (type != GIT_OBJECT_ANY && type != odb_obj->cached.type) { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "the requested type does not match the type in the ODB"); return GIT_ENOTFOUND; } if ((object_size = git_object__size(odb_obj->cached.type)) == 0) { - giterr_set(GITERR_INVALID, "the requested type is invalid"); + git_error_set(GIT_ERROR_INVALID, "the requested type is invalid"); return GIT_ENOTFOUND; } /* Allocate and initialize base object */ object = git__calloc(1, object_size); - GITERR_CHECK_ALLOC(object); + GIT_ERROR_CHECK_ALLOC(object); git_oid_cpy(&object->cached.oid, &odb_obj->cached.oid); object->cached.type = odb_obj->cached.type; @@ -175,7 +175,7 @@ int git_object_lookup_prefix( assert(repo && object_out && id); if (len < GIT_OID_MINPREFIXLEN) { - giterr_set(GITERR_OBJECT, "ambiguous lookup - OID prefix is too short"); + git_error_set(GIT_ERROR_OBJECT, "ambiguous lookup - OID prefix is too short"); return GIT_EAMBIGUOUS; } @@ -199,7 +199,7 @@ int git_object_lookup_prefix( if (type != GIT_OBJECT_ANY && type != object->cached.type) { git_object_free(object); - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "the requested type does not match the type in ODB"); return GIT_ENOTFOUND; } @@ -354,7 +354,7 @@ static int peel_error(int error, const git_oid *oid, git_object_t type) git_oid_fmt(hex_oid, oid); hex_oid[GIT_OID_HEXSZ] = '\0'; - giterr_set(GITERR_OBJECT, "the git_object of id '%s' can not be " + git_error_set(GIT_ERROR_OBJECT, "the git_object of id '%s' can not be " "successfully peeled into a %s (git_object_t=%i).", hex_oid, type_name, type); return error; @@ -469,7 +469,7 @@ int git_object_lookup_bypath( if (type != GIT_OBJECT_ANY && git_tree_entry_type(entry) != type) { - giterr_set(GITERR_OBJECT, + git_error_set(GIT_ERROR_OBJECT, "object at path '%s' is not of the asked-for type %d", path, type); error = GIT_EINVALIDSPEC; @@ -512,7 +512,7 @@ int git_object_short_id(git_buf *out, const git_object *obj) if (error != GIT_EAMBIGUOUS) break; - giterr_clear(); + git_error_clear(); len++; } @@ -542,7 +542,7 @@ bool git_object__is_valid( return false; if (expected_type != GIT_OBJECT_ANY && expected_type != actual_type) { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "the requested type does not match the type in the ODB"); return false; } @@ -78,7 +78,7 @@ static int odb_read_hardcoded(bool *found, git_rawobj *raw, const git_oid *id) raw->type = type; raw->len = 0; raw->data = git__calloc(1, sizeof(uint8_t)); - GITERR_CHECK_ALLOC(raw->data); + GIT_ERROR_CHECK_ALLOC(raw->data); *found = true; return 0; @@ -98,7 +98,7 @@ int git_odb__format_object_header( len = p_snprintf(hdr, hdr_max, "%s %"PRId64, type_str, (int64_t)obj_len); if (len < 0 || len >= hdr_max) { - giterr_set(GITERR_OS, "object header creation failed"); + git_error_set(GIT_ERROR_OS, "object header creation failed"); return -1; } @@ -116,12 +116,12 @@ int git_odb__hashobj(git_oid *id, git_rawobj *obj) assert(id && obj); if (!git_object_typeisloose(obj->type)) { - giterr_set(GITERR_INVALID, "invalid object type"); + git_error_set(GIT_ERROR_INVALID, "invalid object type"); return -1; } if (!obj->data && obj->len != 0) { - giterr_set(GITERR_INVALID, "invalid object"); + git_error_set(GIT_ERROR_INVALID, "invalid object"); return -1; } @@ -204,7 +204,7 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_object_t type) int error = 0; if (!git_object_typeisloose(type)) { - giterr_set(GITERR_INVALID, "invalid object type for hash"); + git_error_set(GIT_ERROR_INVALID, "invalid object type for hash"); return -1; } @@ -229,7 +229,7 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_object_t type) * If size is not zero, the file was truncated after we originally * stat'd it, so we consider this a read failure too */ if (read_len < 0 || size > 0) { - giterr_set(GITERR_OS, "error reading file for hashing"); + git_error_set(GIT_ERROR_OS, "error reading file for hashing"); error = -1; goto done; @@ -281,7 +281,7 @@ int git_odb__hashlink(git_oid *out, const char *path) return -1; if (!git__is_int(st.st_size) || (int)st.st_size < 0) { - giterr_set(GITERR_FILESYSTEM, "file size overflow for 32-bit systems"); + git_error_set(GIT_ERROR_FILESYSTEM, "file size overflow for 32-bit systems"); return -1; } @@ -292,14 +292,14 @@ int git_odb__hashlink(git_oid *out, const char *path) int read_len; size_t alloc_size; - GITERR_CHECK_ALLOC_ADD(&alloc_size, size, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, size, 1); link_data = git__malloc(alloc_size); - GITERR_CHECK_ALLOC(link_data); + GIT_ERROR_CHECK_ALLOC(link_data); read_len = p_readlink(path, link_data, size); link_data[size] = '\0'; if (read_len != size) { - giterr_set(GITERR_OS, "failed to read symlink data for '%s'", path); + git_error_set(GIT_ERROR_OS, "failed to read symlink data for '%s'", path); git__free(link_data); return -1; } @@ -325,7 +325,7 @@ int git_odb_hashfile(git_oid *out, const char *path, git_object_t type) return fd; if ((size = git_futils_filesize(fd)) < 0 || !git__is_sizet(size)) { - giterr_set(GITERR_OS, "file size overflow for 32-bit systems"); + git_error_set(GIT_ERROR_OS, "file size overflow for 32-bit systems"); p_close(fd); return -1; } @@ -389,12 +389,12 @@ static int init_fake_wstream(git_odb_stream **stream_p, git_odb_backend *backend fake_wstream *stream; if (!git__is_ssizet(size)) { - giterr_set(GITERR_ODB, "object size too large to keep in memory"); + git_error_set(GIT_ERROR_ODB, "object size too large to keep in memory"); return -1; } stream = git__calloc(1, sizeof(fake_wstream)); - GITERR_CHECK_ALLOC(stream); + GIT_ERROR_CHECK_ALLOC(stream); stream->size = size; stream->type = type; @@ -441,7 +441,7 @@ static int backend_sort_cmp(const void *a, const void *b) int git_odb_new(git_odb **out) { git_odb *db = git__calloc(1, sizeof(*db)); - GITERR_CHECK_ALLOC(db); + GIT_ERROR_CHECK_ALLOC(db); if (git_cache_init(&db->own_cache) < 0 || git_vector_init(&db->backends, 4, backend_sort_cmp) < 0) { @@ -462,13 +462,13 @@ static int add_backend_internal( assert(odb && backend); - GITERR_CHECK_VERSION(backend, GIT_ODB_BACKEND_VERSION, "git_odb_backend"); + GIT_ERROR_CHECK_VERSION(backend, GIT_ODB_BACKEND_VERSION, "git_odb_backend"); /* Check if the backend is already owned by another ODB */ assert(!backend->odb || backend->odb == odb); internal = git__malloc(sizeof(backend_internal)); - GITERR_CHECK_ALLOC(internal); + GIT_ERROR_CHECK_ALLOC(internal); internal->backend = backend; internal->priority = priority; @@ -503,7 +503,7 @@ size_t git_odb_num_backends(git_odb *odb) static int git_odb__error_unsupported_in_backend(const char *action) { - giterr_set(GITERR_ODB, + git_error_set(GIT_ERROR_ODB, "cannot %s - unsupported in the loaded odb backends", action); return -1; } @@ -521,7 +521,7 @@ int git_odb_get_backend(git_odb_backend **out, git_odb *odb, size_t pos) return 0; } - giterr_set(GITERR_ODB, "no ODB backend loaded at index %" PRIuZ, pos); + git_error_set(GIT_ERROR_ODB, "no ODB backend loaded at index %" PRIuZ, pos); return GIT_ENOTFOUND; } @@ -546,7 +546,7 @@ int git_odb__add_default_backends( if (as_alternates) return 0; - giterr_set(GITERR_ODB, "failed to load object database in '%s'", objects_dir); + git_error_set(GIT_ERROR_ODB, "failed to load object database in '%s'", objects_dir); return -1; } @@ -657,7 +657,7 @@ int git_odb__set_caps(git_odb *odb, int caps) int val; if (!repo) { - giterr_set(GITERR_ODB, "cannot access repository to set odb caps"); + git_error_set(GIT_ERROR_ODB, "cannot access repository to set odb caps"); return -1; } @@ -919,7 +919,7 @@ int git_odb_expand_ids( } } - giterr_clear(); + git_error_clear(); return 0; } @@ -1075,7 +1075,7 @@ static int odb_read_1(git_odb_object **out, git_odb *db, const git_oid *id, } } - giterr_clear(); + git_error_clear(); if ((object = odb_object__alloc(id, &raw)) == NULL) { error = -1; goto out; @@ -1362,7 +1362,7 @@ int git_odb_open_wstream( } ctx = git__malloc(sizeof(git_hash_ctx)); - GITERR_CHECK_ALLOC(ctx); + GIT_ERROR_CHECK_ALLOC(ctx); if ((error = git_hash_ctx_init(ctx)) < 0 || (error = hash_header(ctx, size, type)) < 0) @@ -1382,7 +1382,7 @@ static int git_odb_stream__invalid_length( const git_odb_stream *stream, const char *action) { - giterr_set(GITERR_ODB, + git_error_set(GIT_ERROR_ODB, "cannot %s - " "Invalid length. %"PRId64" was expected. The " "total size of the received chunks amounts to %"PRId64".", @@ -1524,7 +1524,7 @@ int git_odb__error_mismatch(const git_oid *expected, const git_oid *actual) git_oid_tostr(expected_oid, sizeof(expected_oid), expected); git_oid_tostr(actual_oid, sizeof(actual_oid), actual); - giterr_set(GITERR_ODB, "object hash mismatch - expected %s but got %s", + git_error_set(GIT_ERROR_ODB, "object hash mismatch - expected %s but got %s", expected_oid, actual_oid); return GIT_EMISMATCH; @@ -1536,23 +1536,23 @@ int git_odb__error_notfound( if (oid != NULL) { char oid_str[GIT_OID_HEXSZ + 1]; git_oid_tostr(oid_str, oid_len+1, oid); - giterr_set(GITERR_ODB, "object not found - %s (%.*s)", + git_error_set(GIT_ERROR_ODB, "object not found - %s (%.*s)", message, (int) oid_len, oid_str); } else - giterr_set(GITERR_ODB, "object not found - %s", message); + git_error_set(GIT_ERROR_ODB, "object not found - %s", message); return GIT_ENOTFOUND; } static int error_null_oid(int error, const char *message) { - giterr_set(GITERR_ODB, "odb: %s: null OID cannot exist", message); + git_error_set(GIT_ERROR_ODB, "odb: %s: null OID cannot exist", message); return error; } int git_odb__error_ambiguous(const char *message) { - giterr_set(GITERR_ODB, "ambiguous SHA1 prefix - %s", message); + git_error_set(GIT_ERROR_ODB, "ambiguous SHA1 prefix - %s", message); return GIT_EAMBIGUOUS; } diff --git a/src/odb_loose.c b/src/odb_loose.c index 616b8c880..649bc56cb 100644 --- a/src/odb_loose.c +++ b/src/odb_loose.c @@ -81,8 +81,8 @@ static int object_file_name( size_t alloclen; /* expand length for object root + 40 hex sha1 chars + 2 * '/' + '\0' */ - GITERR_CHECK_ALLOC_ADD(&alloclen, be->objects_dirlen, GIT_OID_HEXSZ); - GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, 3); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, be->objects_dirlen, GIT_OID_HEXSZ); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 3); if (git_buf_grow(name, alloclen) < 0) return -1; @@ -138,7 +138,7 @@ static int parse_header_packlike( return 0; on_error: - giterr_set(GITERR_OBJECT, "failed to parse loose object: invalid header"); + git_error_set(GIT_ERROR_OBJECT, "failed to parse loose object: invalid header"); return -1; } @@ -179,7 +179,7 @@ static int parse_header( goto on_error; if ((uint64_t)size > SIZE_MAX) { - giterr_set(GITERR_OBJECT, "object is larger than available memory"); + git_error_set(GIT_ERROR_OBJECT, "object is larger than available memory"); return -1; } @@ -191,7 +191,7 @@ static int parse_header( return 0; on_error: - giterr_set(GITERR_OBJECT, "failed to parse loose object: invalid header"); + git_error_set(GIT_ERROR_OBJECT, "failed to parse loose object: invalid header"); return -1; } @@ -241,7 +241,7 @@ static int read_loose_packlike(git_rawobj *out, git_buf *obj) goto done; if (!git_object_typeisloose(hdr.type) || head_len > obj_len) { - giterr_set(GITERR_ODB, "failed to inflate loose object"); + git_error_set(GIT_ERROR_ODB, "failed to inflate loose object"); error = -1; goto done; } @@ -294,7 +294,7 @@ static int read_loose_standard(git_rawobj *out, git_buf *obj) goto done; if (!git_object_typeisloose(hdr.type)) { - giterr_set(GITERR_ODB, "failed to inflate disk object"); + git_error_set(GIT_ERROR_ODB, "failed to inflate disk object"); error = -1; goto done; } @@ -320,7 +320,7 @@ static int read_loose_standard(git_rawobj *out, git_buf *obj) goto done; if (!git_zstream_done(&zstream)) { - giterr_set(GITERR_ZLIB, "failed to finish zlib inflation: stream aborted prematurely"); + git_error_set(GIT_ERROR_ZLIB, "failed to finish zlib inflation: stream aborted prematurely"); error = -1; goto done; } @@ -427,7 +427,7 @@ static int read_header_loose(git_rawobj *out, git_buf *loc) error = read_header_loose_standard(out, obj, (size_t)obj_len); if (!error && !git_object_typeisloose(out->type)) { - giterr_set(GITERR_ZLIB, "failed to read loose object header"); + git_error_set(GIT_ERROR_ZLIB, "failed to read loose object header"); error = -1; goto done; } @@ -496,8 +496,8 @@ static int locate_object_short_oid( int error; /* prealloc memory for OBJ_DIR/xx/xx..38x..xx */ - GITERR_CHECK_ALLOC_ADD(&alloc_len, dir_len, GIT_OID_HEXSZ); - GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 3); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, GIT_OID_HEXSZ); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 3); if (git_buf_grow(object_location, alloc_len) < 0) return -1; @@ -543,8 +543,8 @@ static int locate_object_short_oid( return error; /* Update the location according to the oid obtained */ - GITERR_CHECK_ALLOC_ADD(&alloc_len, dir_len, GIT_OID_HEXSZ); - GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, GIT_OID_HEXSZ); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2); git_buf_truncate(object_location, dir_len); if (git_buf_grow(object_location, alloc_len) < 0) @@ -731,7 +731,7 @@ static int foreach_object_dir_cb(void *_state, git_buf *path) if (filename_to_oid(&oid, path->ptr + state->dir_len) < 0) return 0; - return giterr_set_after_callback_function( + return git_error_set_after_callback_function( state->cb(&oid, state->data), "git_odb_foreach"); } @@ -838,7 +838,7 @@ static int loose_backend__writestream(git_odb_stream **stream_out, git_odb_backe return error; stream = git__calloc(1, sizeof(loose_writestream)); - GITERR_CHECK_ALLOC(stream); + GIT_ERROR_CHECK_ALLOC(stream); stream->stream.backend = _backend; stream->stream.read = NULL; /* read only */ @@ -926,7 +926,7 @@ static int loose_backend__readstream_packlike( return error; if (!git_object_typeisloose(hdr->type)) { - giterr_set(GITERR_ODB, "failed to inflate loose object"); + git_error_set(GIT_ERROR_ODB, "failed to inflate loose object"); return -1; } @@ -958,7 +958,7 @@ static int loose_backend__readstream_standard( return error; if (!git_object_typeisloose(hdr->type)) { - giterr_set(GITERR_ODB, "failed to inflate disk object"); + git_error_set(GIT_ERROR_ODB, "failed to inflate disk object"); return -1; } @@ -998,10 +998,10 @@ static int loose_backend__readstream( } stream = git__calloc(1, sizeof(loose_readstream)); - GITERR_CHECK_ALLOC(stream); + GIT_ERROR_CHECK_ALLOC(stream); hash_ctx = git__malloc(sizeof(git_hash_ctx)); - GITERR_CHECK_ALLOC(hash_ctx); + GIT_ERROR_CHECK_ALLOC(hash_ctx); if ((error = git_hash_ctx_init(hash_ctx)) < 0 || (error = git_futils_mmap_ro_file(&stream->map, object_path.ptr)) < 0 || @@ -1123,10 +1123,10 @@ int git_odb_backend_loose( objects_dirlen = strlen(objects_dir); - GITERR_CHECK_ALLOC_ADD(&alloclen, sizeof(loose_backend), objects_dirlen); - GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, 2); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(loose_backend), objects_dirlen); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 2); backend = git__calloc(1, alloclen); - GITERR_CHECK_ALLOC(backend); + GIT_ERROR_CHECK_ALLOC(backend); backend->parent.version = GIT_ODB_BACKEND_VERSION; backend->objects_dirlen = objects_dirlen; diff --git a/src/odb_mempack.c b/src/odb_mempack.c index 1086859be..fb29dddd1 100644 --- a/src/odb_mempack.c +++ b/src/odb_mempack.c @@ -48,9 +48,9 @@ static int impl__write(git_odb_backend *_backend, const git_oid *oid, const void if (rval == 0) return 0; - GITERR_CHECK_ALLOC_ADD(&alloc_len, sizeof(struct memobject), len); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, sizeof(struct memobject), len); obj = git__malloc(alloc_len); - GITERR_CHECK_ALLOC(obj); + GIT_ERROR_CHECK_ALLOC(obj); memcpy(obj->data, data, len); git_oid_cpy(&obj->oid, oid); @@ -62,7 +62,7 @@ static int impl__write(git_odb_backend *_backend, const git_oid *oid, const void if (type == GIT_OBJECT_COMMIT) { struct memobject **store = git_array_alloc(db->commits); - GITERR_CHECK_ALLOC(store); + GIT_ERROR_CHECK_ALLOC(store); *store = obj; } @@ -91,7 +91,7 @@ static int impl__read(void **buffer_p, size_t *len_p, git_object_t *type_p, git_ *len_p = obj->len; *type_p = obj->type; *buffer_p = git__malloc(obj->len); - GITERR_CHECK_ALLOC(*buffer_p); + GIT_ERROR_CHECK_ALLOC(*buffer_p); memcpy(*buffer_p, obj->data, obj->len); return 0; @@ -169,7 +169,7 @@ int git_mempack_new(git_odb_backend **out) assert(out); db = git__calloc(1, sizeof(struct memory_packer_db)); - GITERR_CHECK_ALLOC(db); + GIT_ERROR_CHECK_ALLOC(db); db->objects = git_oidmap_alloc(); diff --git a/src/odb_pack.c b/src/odb_pack.c index 6bdedecf9..beab37b7f 100644 --- a/src/odb_pack.c +++ b/src/odb_pack.c @@ -218,7 +218,7 @@ static int packfile_load__cb(void *data, git_buf *path) /* ignore missing .pack file as git does */ if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); return 0; } @@ -533,7 +533,7 @@ static int pack_backend__writepack(struct git_odb_writepack **out, backend = (struct pack_backend *)_backend; writepack = git__calloc(1, sizeof(struct pack_writepack)); - GITERR_CHECK_ALLOC(writepack); + GIT_ERROR_CHECK_ALLOC(writepack); if (git_indexer_new(&writepack->indexer, backend->pack_folder, 0, odb, &opts) < 0) { @@ -573,7 +573,7 @@ static void pack_backend__free(git_odb_backend *_backend) static int pack_backend__alloc(struct pack_backend **out, size_t initial_size) { struct pack_backend *backend = git__calloc(1, sizeof(struct pack_backend)); - GITERR_CHECK_ALLOC(backend); + GIT_ERROR_CHECK_ALLOC(backend); if (git_vector_init(&backend->packs, initial_size, packfile_sort__cb) < 0) { git__free(backend); @@ -17,7 +17,7 @@ static char to_hex[] = "0123456789abcdef"; static int oid_error_invalid(const char *msg) { - giterr_set(GITERR_INVALID, "unable to parse OID - %s", msg); + git_error_set(GIT_ERROR_INVALID, "unable to parse OID - %s", msg); return -1; } @@ -263,7 +263,7 @@ struct git_oid_shorten { static int resize_trie(git_oid_shorten *self, size_t new_size) { self->nodes = git__reallocarray(self->nodes, new_size, sizeof(trie_node)); - GITERR_CHECK_ALLOC(self->nodes); + GIT_ERROR_CHECK_ALLOC(self->nodes); if (new_size > self->size) { memset(&self->nodes[self->size], 0x0, (new_size - self->size) * sizeof(trie_node)); @@ -381,7 +381,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid) node_index idx; if (os->full) { - giterr_set(GITERR_INVALID, "unable to shorten OID - OID set full"); + git_error_set(GIT_ERROR_INVALID, "unable to shorten OID - OID set full"); return -1; } @@ -396,7 +396,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid) trie_node *node; if (c == -1) { - giterr_set(GITERR_INVALID, "unable to shorten OID - invalid hex value"); + git_error_set(GIT_ERROR_INVALID, "unable to shorten OID - invalid hex value"); return -1; } @@ -411,7 +411,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid) node = push_leaf(os, idx, git__fromhex(tail[0]), &tail[1]); if (node == NULL) { if (os->full) - giterr_set(GITERR_INVALID, "unable to shorten OID - OID set full"); + git_error_set(GIT_ERROR_INVALID, "unable to shorten OID - OID set full"); return -1; } } @@ -419,7 +419,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid) if (node->children[c] == 0) { if (push_leaf(os, idx, c, &text_oid[i + 1]) == NULL) { if (os->full) - giterr_set(GITERR_INVALID, "unable to shorten OID - OID set full"); + git_error_set(GIT_ERROR_INVALID, "unable to shorten OID - OID set full"); return -1; } break; diff --git a/src/pack-objects.c b/src/pack-objects.c index a57a6bb4c..e1528646a 100644 --- a/src/pack-objects.c +++ b/src/pack-objects.c @@ -105,7 +105,7 @@ static int packbuilder_config(git_packbuilder *pb) ret = git_config_get_int64(&val, config, KEY); \ if (!ret) { \ if (!git__is_sizet(val)) { \ - giterr_set(GITERR_CONFIG, \ + git_error_set(GIT_ERROR_CONFIG, \ "configuration value '%s' is too large", KEY); \ ret = -1; \ goto out; \ @@ -139,7 +139,7 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo) *out = NULL; pb = git__calloc(1, sizeof(*pb)); - GITERR_CHECK_ALLOC(pb); + GIT_ERROR_CHECK_ALLOC(pb); pb->object_ix = git_oidmap_alloc(); if (!pb->object_ix) @@ -166,7 +166,7 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo) git_mutex_init(&pb->progress_mutex) || git_cond_init(&pb->progress_cond)) { - giterr_set(GITERR_OS, "failed to initialize packbuilder mutex"); + git_error_set(GIT_ERROR_OS, "failed to initialize packbuilder mutex"); goto on_error; } @@ -222,11 +222,11 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid, return 0; if (pb->nr_objects >= pb->nr_alloc) { - GITERR_CHECK_ALLOC_ADD(&newsize, pb->nr_alloc, 1024); - GITERR_CHECK_ALLOC_MULTIPLY(&newsize, newsize, 3 / 2); + GIT_ERROR_CHECK_ALLOC_ADD(&newsize, pb->nr_alloc, 1024); + GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newsize, newsize, 3 / 2); if (!git__is_uint32(newsize)) { - giterr_set(GITERR_NOMEMORY, "packfile too large to fit in memory."); + git_error_set(GIT_ERROR_NOMEMORY, "packfile too large to fit in memory."); return -1; } @@ -234,7 +234,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid, pb->object_list = git__reallocarray(pb->object_list, pb->nr_alloc, sizeof(*po)); - GITERR_CHECK_ALLOC(pb->object_list); + GIT_ERROR_CHECK_ALLOC(pb->object_list); rehash(pb); } @@ -250,7 +250,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid, pos = git_oidmap_put(pb->object_ix, &po->id, &ret); if (ret < 0) { - giterr_set_oom(); + git_error_set_oom(); return ret; } assert(ret != 0); @@ -270,7 +270,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid, pb->nr_objects, 0, pb->progress_cb_payload); if (ret) - return giterr_set_after_callback(ret); + return git_error_set_after_callback(ret); } } @@ -299,7 +299,7 @@ static int get_delta(void **out, git_odb *odb, git_pobject *po) goto on_error; if (error == GIT_EBUFS || delta_size != po->delta_size) { - giterr_set(GITERR_INVALID, "delta size changed"); + git_error_set(GIT_ERROR_INVALID, "delta size changed"); goto on_error; } @@ -372,7 +372,7 @@ static int write_object( goto done; } else { zbuf = git__malloc(zbuf_len); - GITERR_CHECK_ALLOC(zbuf); + GIT_ERROR_CHECK_ALLOC(zbuf); git_zstream_reset(&pb->zstream); git_zstream_set_input(&pb->zstream, data, data_len); @@ -621,7 +621,7 @@ static git_pobject **compute_write_order(git_packbuilder *pb) if (wo_end != pb->nr_objects) { git__free(wo); - giterr_set(GITERR_INVALID, "invalid write order"); + git_error_set(GIT_ERROR_INVALID, "invalid write order"); return NULL; } @@ -645,7 +645,7 @@ static int write_pack(git_packbuilder *pb, return -1; if (!git__is_uint32(pb->nr_objects)) { - giterr_set(GITERR_INVALID, "too many objects"); + git_error_set(GIT_ERROR_INVALID, "too many objects"); return -1; } @@ -802,13 +802,13 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg, sz = git_odb_object_size(obj); trg->data = git__malloc(sz); - GITERR_CHECK_ALLOC(trg->data); + GIT_ERROR_CHECK_ALLOC(trg->data); memcpy(trg->data, git_odb_object_data(obj), sz); git_odb_object_free(obj); if (sz != trg_size) { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "inconsistent target object length"); return -1; } @@ -824,13 +824,13 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg, sz = obj_sz; src->data = git__malloc(sz); - GITERR_CHECK_ALLOC(src->data); + GIT_ERROR_CHECK_ALLOC(src->data); memcpy(src->data, git_odb_object_data(obj), sz); git_odb_object_free(obj); if (sz != src_size) { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "inconsistent source object length"); return -1; } @@ -876,7 +876,7 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg, } trg_object->delta_data = git__realloc(delta_buf, delta_size); - GITERR_CHECK_ALLOC(trg_object->delta_data); + GIT_ERROR_CHECK_ALLOC(trg_object->delta_data); } else { /* create delta when writing the pack */ git_packbuilder__cache_unlock(pb); @@ -942,7 +942,7 @@ static int report_delta_progress( count, pb->nr_objects, pb->progress_cb_payload); if (ret) - return giterr_set_after_callback(ret); + return git_error_set_after_callback(ret); } } @@ -961,7 +961,7 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list, int error = -1; array = git__calloc(window, sizeof(struct unpacked)); - GITERR_CHECK_ALLOC(array); + GIT_ERROR_CHECK_ALLOC(array); for (;;) { struct unpacked *n = array + idx; @@ -1047,7 +1047,7 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list, git__free(po->delta_data); po->delta_data = git__malloc(zbuf.size); - GITERR_CHECK_ALLOC(po->delta_data); + GIT_ERROR_CHECK_ALLOC(po->delta_data); memcpy(po->delta_data, zbuf.ptr, zbuf.size); po->z_delta_size = zbuf.size; @@ -1140,7 +1140,7 @@ static void *threaded_find_deltas(void *arg) git_packbuilder__progress_unlock(me->pb); if (git_mutex_lock(&me->mutex)) { - giterr_set(GITERR_THREAD, "unable to lock packfile condition mutex"); + git_error_set(GIT_ERROR_THREAD, "unable to lock packfile condition mutex"); return NULL; } @@ -1178,7 +1178,7 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list, } p = git__mallocarray(pb->nr_threads, sizeof(*p)); - GITERR_CHECK_ALLOC(p); + GIT_ERROR_CHECK_ALLOC(p); /* Partition the work among the threads */ for (i = 0; i < pb->nr_threads; ++i) { @@ -1219,7 +1219,7 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list, ret = git_thread_create(&p[i].thread, threaded_find_deltas, &p[i]); if (ret) { - giterr_set(GITERR_THREAD, "unable to create thread"); + git_error_set(GIT_ERROR_THREAD, "unable to create thread"); return -1; } active_threads++; @@ -1288,7 +1288,7 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list, git_packbuilder__progress_unlock(pb); if (git_mutex_lock(&target->mutex)) { - giterr_set(GITERR_THREAD, "unable to lock packfile condition mutex"); + git_error_set(GIT_ERROR_THREAD, "unable to lock packfile condition mutex"); git__free(p); return -1; } @@ -1329,7 +1329,7 @@ static int prepare_pack(git_packbuilder *pb) pb->progress_cb(GIT_PACKBUILDER_DELTAFICATION, 0, pb->nr_objects, pb->progress_cb_payload); delta_list = git__mallocarray(pb->nr_objects, sizeof(*delta_list)); - GITERR_CHECK_ALLOC(delta_list); + GIT_ERROR_CHECK_ALLOC(delta_list); for (i = 0; i < pb->nr_objects; ++i) { git_pobject *po = pb->object_list + i; @@ -1502,7 +1502,7 @@ int git_packbuilder_insert_recur(git_packbuilder *pb, const git_oid *id, const c break; default: - giterr_set(GITERR_INVALID, "unknown object type"); + git_error_set(GIT_ERROR_INVALID, "unknown object type"); error = -1; } @@ -1527,7 +1527,7 @@ static int lookup_walk_object(struct walk_object **out, git_packbuilder *pb, con obj = git_pool_mallocz(&pb->object_pool, 1); if (!obj) { - giterr_set_oom(); + git_error_set_oom(); return -1; } diff --git a/src/pack.c b/src/pack.c index 86c8c7256..ef360a90b 100644 --- a/src/pack.c +++ b/src/pack.c @@ -42,7 +42,7 @@ static int pack_entry_find_offset( static int packfile_error(const char *message) { - giterr_set(GITERR_ODB, "invalid pack file - %s", message); + git_error_set(GIT_ERROR_ODB, "invalid pack file - %s", message); return -1; } @@ -90,12 +90,12 @@ static void cache_free(git_pack_cache *cache) static int cache_init(git_pack_cache *cache) { cache->entries = git_offmap_alloc(); - GITERR_CHECK_ALLOC(cache->entries); + GIT_ERROR_CHECK_ALLOC(cache->entries); cache->memory_limit = GIT_PACK_CACHE_MEMORY_LIMIT; if (git_mutex_init(&cache->lock)) { - giterr_set(GITERR_OS, "failed to initialize pack cache mutex"); + git_error_set(GIT_ERROR_OS, "failed to initialize pack cache mutex"); git__free(cache->entries); cache->entries = NULL; @@ -156,7 +156,7 @@ static int cache_add( entry = new_cache_object(base); if (entry) { if (git_mutex_lock(&cache->lock) < 0) { - giterr_set(GITERR_OS, "failed to lock cache"); + git_error_set(GIT_ERROR_OS, "failed to lock cache"); git__free(entry); return -1; } @@ -217,7 +217,7 @@ static int pack_index_check(const char *path, struct git_pack_file *p) if (p_fstat(fd, &st) < 0) { p_close(fd); - giterr_set(GITERR_OS, "unable to stat pack index '%s'", path); + git_error_set(GIT_ERROR_OS, "unable to stat pack index '%s'", path); return -1; } @@ -226,7 +226,7 @@ static int pack_index_check(const char *path, struct git_pack_file *p) (idx_size = (size_t)st.st_size) < 4 * 256 + 20 + 20) { p_close(fd); - giterr_set(GITERR_ODB, "invalid pack index '%s'", path); + git_error_set(GIT_ERROR_ODB, "invalid pack index '%s'", path); return -1; } @@ -419,13 +419,13 @@ static int packfile_unpack_header1( shift = 4; while (c & 0x80) { if (len <= used) { - giterr_set(GITERR_ODB, "buffer too small"); + git_error_set(GIT_ERROR_ODB, "buffer too small"); return GIT_EBUFS; } if (bitsizeof(long) <= shift) { *usedp = 0; - giterr_set(GITERR_ODB, "packfile corrupted"); + git_error_set(GIT_ERROR_ODB, "packfile corrupted"); return -1; } @@ -557,7 +557,7 @@ static int pack_dependency_chain(git_dependency_chain *chain_out, /* if we run out of space on the small stack, use the array */ if (elem_pos == SMALL_STACK_SIZE) { git_array_init_to_size(chain, elem_pos); - GITERR_CHECK_ARRAY(chain); + GIT_ERROR_CHECK_ARRAY(chain); memcpy(chain.ptr, small_stack, elem_pos * sizeof(struct pack_chain_elem)); chain.size = elem_pos; use_heap = 1; @@ -691,9 +691,9 @@ int git_packfile_unpack( if (cached && stack_size == 1) { void *data = obj->data; - GITERR_CHECK_ALLOC_ADD(&alloclen, obj->len, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, obj->len, 1); obj->data = git__malloc(alloclen); - GITERR_CHECK_ALLOC(obj->data); + GIT_ERROR_CHECK_ALLOC(obj->data); memcpy(obj->data, data, obj->len + 1); git_atomic_dec(&cached->refcount); @@ -793,7 +793,7 @@ int git_packfile_stream_open(git_packfile_stream *obj, struct git_pack_file *p, obj->zstream.next_out = Z_NULL; st = inflateInit(&obj->zstream); if (st != Z_OK) { - giterr_set(GITERR_ZLIB, "failed to init packfile stream"); + git_error_set(GIT_ERROR_ZLIB, "failed to init packfile stream"); return -1; } @@ -824,7 +824,7 @@ ssize_t git_packfile_stream_read(git_packfile_stream *obj, void *buffer, size_t written = len - obj->zstream.avail_out; if (st != Z_OK && st != Z_STREAM_END) { - giterr_set(GITERR_ZLIB, "error reading from the zlib stream"); + git_error_set(GIT_ERROR_ZLIB, "error reading from the zlib stream"); return -1; } @@ -858,9 +858,9 @@ static int packfile_unpack_compressed( z_stream stream; unsigned char *buffer, *in; - GITERR_CHECK_ALLOC_ADD(&buf_size, size, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&buf_size, size, 1); buffer = git__calloc(1, buf_size); - GITERR_CHECK_ALLOC(buffer); + GIT_ERROR_CHECK_ALLOC(buffer); memset(&stream, 0, sizeof(stream)); stream.next_out = buffer; @@ -871,7 +871,7 @@ static int packfile_unpack_compressed( st = inflateInit(&stream); if (st != Z_OK) { git__free(buffer); - giterr_set(GITERR_ZLIB, "failed to init zlib stream on unpack"); + git_error_set(GIT_ERROR_ZLIB, "failed to init zlib stream on unpack"); return -1; } @@ -898,7 +898,7 @@ static int packfile_unpack_compressed( if ((st != Z_STREAM_END) || stream.total_out != size) { git__free(buffer); - giterr_set(GITERR_ZLIB, "error inflating zlib stream"); + git_error_set(GIT_ERROR_ZLIB, "error inflating zlib stream"); return -1; } @@ -1087,7 +1087,7 @@ static int packfile_open(struct git_pack_file *p) return 0; cleanup: - giterr_set(GITERR_OS, "invalid packfile '%s'", p->pack_name); + git_error_set(GIT_ERROR_OS, "invalid packfile '%s'", p->pack_name); if (p->mwf.fd >= 0) p_close(p->mwf.fd); @@ -1126,11 +1126,11 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path) if (path_len < strlen(".idx")) return git_odb__error_notfound("invalid packfile path", NULL, 0); - GITERR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*p), path_len); - GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*p), path_len); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2); p = git__calloc(1, alloc_len); - GITERR_CHECK_ALLOC(p); + GIT_ERROR_CHECK_ALLOC(p); memcpy(p->pack_name, path, path_len + 1); @@ -1163,7 +1163,7 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path) p->index_version = -1; if (git_mutex_init(&p->lock)) { - giterr_set(GITERR_OS, "failed to initialize packfile mutex"); + git_error_set(GIT_ERROR_OS, "failed to initialize packfile mutex"); git__free(p); return -1; } @@ -1266,7 +1266,7 @@ int git_pack_foreach_entry( for (i = 0; i < p->num_objects; i++) if ((error = cb(p->oids[i], data)) != 0) - return giterr_set_after_callback(error); + return git_error_set_after_callback(error); return error; } @@ -1352,7 +1352,7 @@ static int pack_entry_find_offset( return git_odb__error_ambiguous("found multiple offsets for pack entry"); if ((offset = nth_packed_object_offset(p, pos)) < 0) { - giterr_set(GITERR_ODB, "packfile index is corrupt"); + git_error_set(GIT_ERROR_ODB, "packfile index is corrupt"); return -1; } diff --git a/src/parse.h b/src/parse.h index 46897e306..21dcf9bd1 100644 --- a/src/parse.h +++ b/src/parse.h @@ -27,7 +27,7 @@ int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_l void git_parse_ctx_clear(git_parse_ctx *ctx); #define git_parse_err(...) \ - ( giterr_set(GITERR_PATCH, __VA_ARGS__), -1 ) + ( git_error_set(GIT_ERROR_PATCH, __VA_ARGS__), -1 ) #define git_parse_ctx_contains_s(ctx, str) \ git_parse_ctx_contains(ctx, str, sizeof(str) - 1) diff --git a/src/patch.c b/src/patch.c index 15d2ca811..d19e6833e 100644 --- a/src/patch.c +++ b/src/patch.c @@ -80,7 +80,7 @@ size_t git_patch_size( if (git_diff_delta__format_file_header( &file_header, patch->delta, NULL, NULL, 0) < 0) - giterr_clear(); + git_error_clear(); else out += git_buf_len(&file_header); @@ -141,7 +141,7 @@ size_t git_patch_num_hunks(const git_patch *patch) static int patch_error_outofrange(const char *thing) { - giterr_set(GITERR_INVALID, "patch %s index out of range", thing); + git_error_set(GIT_ERROR_INVALID, "patch %s index out of range", thing); return GIT_ENOTFOUND; } diff --git a/src/patch_generate.c b/src/patch_generate.c index 800d0e2b1..80033ee53 100644 --- a/src/patch_generate.c +++ b/src/patch_generate.c @@ -84,7 +84,7 @@ static int patch_generated_normalize_options( const git_diff_options *opts) { if (opts) { - GITERR_CHECK_VERSION(opts, GIT_DIFF_OPTIONS_VERSION, "git_diff_options"); + GIT_ERROR_CHECK_VERSION(opts, GIT_DIFF_OPTIONS_VERSION, "git_diff_options"); memcpy(out, opts, sizeof(git_diff_options)); } else { git_diff_options default_opts = GIT_DIFF_OPTIONS_INIT; @@ -99,8 +99,8 @@ static int patch_generated_normalize_options( git__strdup(opts->new_prefix) : git__strdup(DIFF_NEW_PREFIX_DEFAULT); - GITERR_CHECK_ALLOC(out->old_prefix); - GITERR_CHECK_ALLOC(out->new_prefix); + GIT_ERROR_CHECK_ALLOC(out->old_prefix); + GIT_ERROR_CHECK_ALLOC(out->new_prefix); return 0; } @@ -135,7 +135,7 @@ static int patch_generated_alloc_from_diff( { int error; git_patch_generated *patch = git__calloc(1, sizeof(git_patch_generated)); - GITERR_CHECK_ALLOC(patch); + GIT_ERROR_CHECK_ALLOC(patch); if (!(error = patch_generated_init(patch, diff, delta_index))) { patch->flags |= GIT_PATCH_GENERATED_ALLOCATED; @@ -248,7 +248,7 @@ static int patch_generated_invoke_file_callback( if (!output->file_cb) return 0; - return giterr_set_after_callback_function( + return git_error_set_after_callback_function( output->file_cb(patch->base.delta, progress, output->payload), "git_patch"); } @@ -350,7 +350,7 @@ static int diff_binary(git_patch_generated_output *output, git_patch_generated * return error; } - error = giterr_set_after_callback_function( + error = git_error_set_after_callback_function( output->binary_cb(patch->base.delta, &binary, output->payload), "git_patch"); @@ -397,7 +397,7 @@ static int diff_required(git_diff *diff, const char *action) { if (diff) return 0; - giterr_set(GITERR_INVALID, "must provide valid diff to %s", action); + git_error_set(GIT_ERROR_INVALID, "must provide valid diff to %s", action); return -1; } @@ -501,12 +501,12 @@ static int patch_generated_with_delta_alloc( size_t new_len = *new_path ? strlen(*new_path) : 0; size_t alloc_len; - GITERR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*pd), old_len); - GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, new_len); - GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*pd), old_len); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, new_len); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2); *out = pd = git__calloc(1, alloc_len); - GITERR_CHECK_ALLOC(pd); + GIT_ERROR_CHECK_ALLOC(pd); pd->patch.flags = GIT_PATCH_GENERATED_ALLOCATED; @@ -708,7 +708,7 @@ int git_patch_generated_from_diff( delta = git_vector_get(&diff->deltas, idx); if (!delta) { - giterr_set(GITERR_INVALID, "index out of range for delta in diff"); + git_error_set(GIT_ERROR_INVALID, "index out of range for delta in diff"); return GIT_ENOTFOUND; } @@ -788,7 +788,7 @@ static int patch_generated_binary_cb( if (binary->old_file.data) { patch->binary.old_file.data = git__malloc(binary->old_file.datalen); - GITERR_CHECK_ALLOC(patch->binary.old_file.data); + GIT_ERROR_CHECK_ALLOC(patch->binary.old_file.data); memcpy((char *)patch->binary.old_file.data, binary->old_file.data, binary->old_file.datalen); @@ -796,7 +796,7 @@ static int patch_generated_binary_cb( if (binary->new_file.data) { patch->binary.new_file.data = git__malloc(binary->new_file.datalen); - GITERR_CHECK_ALLOC(patch->binary.new_file.data); + GIT_ERROR_CHECK_ALLOC(patch->binary.new_file.data); memcpy((char *)patch->binary.new_file.data, binary->new_file.data, binary->new_file.datalen); @@ -816,7 +816,7 @@ static int git_patch_hunk_cb( GIT_UNUSED(delta); hunk = git_array_alloc(patch->base.hunks); - GITERR_CHECK_ALLOC(hunk); + GIT_ERROR_CHECK_ALLOC(hunk); memcpy(&hunk->hunk, hunk_, sizeof(hunk->hunk)); @@ -845,7 +845,7 @@ static int patch_generated_line_cb( assert(hunk); /* programmer error if no hunk is available */ line = git_array_alloc(patch->base.lines); - GITERR_CHECK_ALLOC(line); + GIT_ERROR_CHECK_ALLOC(line); memcpy(line, line_, sizeof(*line)); diff --git a/src/patch_parse.c b/src/patch_parse.c index 0244dbb52..1bf3ad861 100644 --- a/src/patch_parse.c +++ b/src/patch_parse.c @@ -518,7 +518,7 @@ static int parse_hunk_header( return 0; fail: - giterr_set(GITERR_PATCH, "invalid patch hunk header at line %"PRIuZ, + git_error_set(GIT_ERROR_PATCH, "invalid patch hunk header at line %"PRIuZ, ctx->parse_ctx.line_num); return -1; } @@ -583,7 +583,7 @@ static int parse_hunk_body( } line = git_array_alloc(patch->base.lines); - GITERR_CHECK_ALLOC(line); + GIT_ERROR_CHECK_ALLOC(line); memset(line, 0x0, sizeof(git_diff_line)); @@ -650,7 +650,7 @@ static int parse_patch_header( * noise, continue. */ if (parse_hunk_header(&hunk, ctx) < 0) { - giterr_clear(); + git_error_clear(); continue; } @@ -673,7 +673,7 @@ static int parse_patch_header( continue; } - giterr_set(GITERR_PATCH, "no patch found"); + git_error_set(GIT_ERROR_PATCH, "no patch found"); error = GIT_ENOTFOUND; done: @@ -821,7 +821,7 @@ static int parse_patch_hunks( while (git_parse_ctx_contains_s(&ctx->parse_ctx, "@@ -")) { hunk = git_array_alloc(patch->base.hunks); - GITERR_CHECK_ALLOC(hunk); + GIT_ERROR_CHECK_ALLOC(hunk); memset(hunk, 0, sizeof(git_patch_hunk)); @@ -1079,7 +1079,7 @@ int git_patch_parse( *out = NULL; patch = git__calloc(1, sizeof(git_patch_parsed)); - GITERR_CHECK_ALLOC(patch); + GIT_ERROR_CHECK_ALLOC(patch); patch->ctx = ctx; GIT_REFCOUNT_INC(patch->ctx); @@ -1087,7 +1087,7 @@ int git_patch_parse( patch->base.free_fn = patch_parsed__free; patch->base.delta = git__calloc(1, sizeof(git_diff_delta)); - GITERR_CHECK_ALLOC(patch->base.delta); + GIT_ERROR_CHECK_ALLOC(patch->base.delta); patch->base.delta->status = GIT_DELTA_MODIFIED; patch->base.delta->nfiles = 2; @@ -1126,7 +1126,7 @@ int git_patch_from_buffer( int error; ctx = git_patch_parse_ctx_init(content, content_len, opts); - GITERR_CHECK_ALLOC(ctx); + GIT_ERROR_CHECK_ALLOC(ctx); error = git_patch_parse(out, ctx); diff --git a/src/path.c b/src/path.c index 9fab29e8b..197efb75a 100644 --- a/src/path.c +++ b/src/path.c @@ -361,9 +361,9 @@ int git_path_prettify(git_buf *path_out, const char *path, const char *base) } if (p_realpath(path, buf) == NULL) { - /* giterr_set resets the errno when dealing with a GITERR_OS kind of error */ + /* git_error_set resets the errno when dealing with a GIT_ERROR_OS kind of error */ int error = (errno == ENOENT || errno == ENOTDIR) ? GIT_ENOTFOUND : -1; - giterr_set(GITERR_OS, "failed to resolve path '%s'", path); + git_error_set(GIT_ERROR_OS, "failed to resolve path '%s'", path); git_buf_clear(path_out); @@ -436,7 +436,7 @@ append: static int error_invalid_local_file_uri(const char *uri) { - giterr_set(GITERR_CONFIG, "'%s' is not a valid local file URI", uri); + git_error_set(GIT_ERROR_CONFIG, "'%s' is not a valid local file URI", uri); return -1; } @@ -502,7 +502,7 @@ int git_path_walk_up( if (!scan) { error = cb(data, ""); if (error) - giterr_set_after_callback(error); + git_error_set_after_callback(error); return error; } @@ -515,7 +515,7 @@ int git_path_walk_up( iter.ptr[scan] = oldc; if (error) { - giterr_set_after_callback(error); + git_error_set_after_callback(error); break; } @@ -535,7 +535,7 @@ int git_path_walk_up( if (!error && stop == 0 && iter.ptr[0] != '/') { error = cb(data, ""); if (error) - giterr_set_after_callback(error); + git_error_set_after_callback(error); } return error; @@ -638,7 +638,7 @@ bool git_path_is_empty_dir(const char *path) return false; if ((error = git_buf_sets(&dir, path)) != 0) - giterr_clear(); + git_error_clear(); else error = git_path_direach(&dir, 0, path_found_entry, NULL); @@ -654,24 +654,24 @@ int git_path_set_error(int errno_value, const char *path, const char *action) switch (errno_value) { case ENOENT: case ENOTDIR: - giterr_set(GITERR_OS, "could not find '%s' to %s", path, action); + git_error_set(GIT_ERROR_OS, "could not find '%s' to %s", path, action); return GIT_ENOTFOUND; case EINVAL: case ENAMETOOLONG: - giterr_set(GITERR_OS, "invalid path for filesystem '%s'", path); + git_error_set(GIT_ERROR_OS, "invalid path for filesystem '%s'", path); return GIT_EINVALIDSPEC; case EEXIST: - giterr_set(GITERR_OS, "failed %s - '%s' already exists", action, path); + git_error_set(GIT_ERROR_OS, "failed %s - '%s' already exists", action, path); return GIT_EEXISTS; case EACCES: - giterr_set(GITERR_OS, "failed %s - '%s' is locked", action, path); + git_error_set(GIT_ERROR_OS, "failed %s - '%s' is locked", action, path); return GIT_ELOCKED; default: - giterr_set(GITERR_OS, "could not %s '%s'", action, path); + git_error_set(GIT_ERROR_OS, "could not %s '%s'", action, path); return -1; } } @@ -751,7 +751,7 @@ int git_path_resolve_relative(git_buf *path, size_t ceiling) char *base, *to, *from, *next; size_t len; - GITERR_CHECK_ALLOC_BUF(path); + GIT_ERROR_CHECK_ALLOC_BUF(path); if (ceiling > path->size) ceiling = path->size; @@ -780,7 +780,7 @@ int git_path_resolve_relative(git_buf *path, size_t ceiling) else if (len == 2 && from[0] == '.' && from[1] == '.') { /* error out if trying to up one from a hard base */ if (to == base && ceiling != 0) { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "cannot strip root component off url"); return -1; } @@ -887,7 +887,7 @@ int git_path_make_relative(git_buf *path, const char *parent) /* need at least 1 common path segment */ if ((p_dirsep == path->ptr || q_dirsep == parent) && (*p_dirsep != '/' || *q_dirsep != '/')) { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "%s is not a parent of %s", parent, path->ptr); return GIT_ENOTFOUND; } @@ -911,10 +911,10 @@ int git_path_make_relative(git_buf *path, const char *parent) for (; (q = strchr(q, '/')) && *(q + 1); q++) depth++; - GITERR_CHECK_ALLOC_MULTIPLY(&newlen, depth, 3); - GITERR_CHECK_ALLOC_ADD(&newlen, newlen, plen); + GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newlen, depth, 3); + GIT_ERROR_CHECK_ALLOC_ADD(&newlen, newlen, plen); - GITERR_CHECK_ALLOC_ADD(&alloclen, newlen, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, newlen, 1); /* save the offset as we might realllocate the pointer */ offset = p - path->ptr; @@ -973,7 +973,7 @@ int git_path_iconv(git_path_iconv_t *ic, const char **in, size_t *inlen) git_buf_clear(&ic->buf); while (1) { - GITERR_CHECK_ALLOC_ADD(&alloclen, wantlen, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, wantlen, 1); if (git_buf_grow(&ic->buf, alloclen) < 0) return -1; @@ -1010,7 +1010,7 @@ int git_path_iconv(git_path_iconv_t *ic, const char **in, size_t *inlen) return 0; fail: - giterr_set(GITERR_OS, "unable to convert unicode path data"); + git_error_set(GIT_ERROR_OS, "unable to convert unicode path data"); return -1; } @@ -1103,7 +1103,7 @@ int git_path_direach( wd_len = git_buf_len(path); if ((dir = opendir(path->ptr)) == NULL) { - giterr_set(GITERR_OS, "failed to open directory '%s'", path->ptr); + git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path->ptr); if (errno == ENOENT) return GIT_ENOTFOUND; @@ -1130,15 +1130,15 @@ int git_path_direach( if ((error = git_buf_put(path, de_path, de_len)) < 0) break; - giterr_clear(); + git_error_clear(); error = fn(arg, path); git_buf_truncate(path, wd_len); /* restore path */ /* Only set our own error if the callback did not set one already */ if (error != 0) { - if (!giterr_last()) - giterr_set_after_callback(error); + if (!git_error_last()) + git_error_set_after_callback(error); break; } @@ -1184,13 +1184,13 @@ int git_path_diriter_init( git_path_trim_slashes(&diriter->path_utf8); if (diriter->path_utf8.size == 0) { - giterr_set(GITERR_FILESYSTEM, "could not open directory '%s'", path); + git_error_set(GIT_ERROR_FILESYSTEM, "could not open directory '%s'", path); return -1; } if ((diriter->parent_len = git_win32_path_from_utf8(diriter->path, diriter->path_utf8.ptr)) < 0 || !git_win32__findfirstfile_filter(path_filter, diriter->path_utf8.ptr)) { - giterr_set(GITERR_OS, "could not parse the directory path '%s'", path); + git_error_set(GIT_ERROR_OS, "could not parse the directory path '%s'", path); return -1; } @@ -1203,7 +1203,7 @@ int git_path_diriter_init( is_win7_or_later ? FIND_FIRST_EX_LARGE_FETCH : 0); if (diriter->handle == INVALID_HANDLE_VALUE) { - giterr_set(GITERR_OS, "could not open directory '%s'", path); + git_error_set(GIT_ERROR_OS, "could not open directory '%s'", path); return -1; } @@ -1223,7 +1223,7 @@ static int diriter_update_paths(git_path_diriter *diriter) return -1; if (path_len > GIT_WIN_PATH_UTF16) { - giterr_set(GITERR_FILESYSTEM, + git_error_set(GIT_ERROR_FILESYSTEM, "invalid path '%.*ls\\%ls' (path too long)", diriter->parent_len, diriter->path, diriter->current.cFileName); return -1; @@ -1333,14 +1333,14 @@ int git_path_diriter_init( git_path_trim_slashes(&diriter->path); if (diriter->path.size == 0) { - giterr_set(GITERR_FILESYSTEM, "could not open directory '%s'", path); + git_error_set(GIT_ERROR_FILESYSTEM, "could not open directory '%s'", path); return -1; } if ((diriter->dir = opendir(diriter->path.ptr)) == NULL) { git_buf_dispose(&diriter->path); - giterr_set(GITERR_OS, "failed to open directory '%s'", path); + git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path); return -1; } @@ -1372,7 +1372,7 @@ int git_path_diriter_next(git_path_diriter *diriter) if (!errno) return GIT_ITEROVER; - giterr_set(GITERR_OS, + git_error_set(GIT_ERROR_OS, "could not read directory '%s'", diriter->path.ptr); return -1; } @@ -1477,7 +1477,7 @@ int git_path_dirload( assert(name_len > prefix_len); dup = git__strndup(name + prefix_len, name_len - prefix_len); - GITERR_CHECK_ALLOC(dup); + GIT_ERROR_CHECK_ALLOC(dup); if ((error = git_vector_insert(contents, dup)) < 0) break; @@ -1888,7 +1888,7 @@ extern int git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfil size_t filelen; if (!(gitfile >= GIT_PATH_GITFILE_GITIGNORE && gitfile < ARRAY_SIZE(gitfiles))) { - giterr_set(GITERR_OS, "invalid gitfile for path validation"); + git_error_set(GIT_ERROR_OS, "invalid gitfile for path validation"); return -1; } @@ -1905,7 +1905,7 @@ extern int git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfil case GIT_PATH_FS_HFS: return !verify_dotgit_hfs_generic(path, pathlen, file, filelen); default: - giterr_set(GITERR_OS, "invalid filesystem for path validation"); + git_error_set(GIT_ERROR_OS, "invalid filesystem for path validation"); return -1; } } diff --git a/src/pathspec.c b/src/pathspec.c index 3415f66e5..07795f256 100644 --- a/src/pathspec.c +++ b/src/pathspec.c @@ -258,7 +258,7 @@ int git_pathspec_new(git_pathspec **out, const git_strarray *pathspec) { int error = 0; git_pathspec *ps = git__malloc(sizeof(git_pathspec)); - GITERR_CHECK_ALLOC(ps); + GIT_ERROR_CHECK_ALLOC(ps); if ((error = git_pathspec__init(ps, pathspec)) < 0) { git__free(ps); @@ -416,7 +416,7 @@ static int pathspec_match_from_iterator( if (out) { *out = m = pathspec_match_alloc(ps, PATHSPEC_DATATYPE_STRINGS); - GITERR_CHECK_ALLOC(m); + GIT_ERROR_CHECK_ALLOC(m); } if ((error = git_iterator_reset_range(iter, ps->prefix, ps->prefix)) < 0) @@ -488,7 +488,7 @@ static int pathspec_match_from_iterator( /* if every pattern failed to match, then we have failed */ if ((flags & GIT_PATHSPEC_NO_MATCH_ERROR) != 0 && !found_files) { - giterr_set(GITERR_INVALID, "no matching files were found"); + git_error_set(GIT_ERROR_INVALID, "no matching files were found"); error = GIT_ENOTFOUND; } @@ -604,7 +604,7 @@ int git_pathspec_match_diff( if (out) { *out = m = pathspec_match_alloc(ps, PATHSPEC_DATATYPE_DIFF); - GITERR_CHECK_ALLOC(m); + GIT_ERROR_CHECK_ALLOC(m); } pathspec_match_context_init( @@ -659,7 +659,7 @@ int git_pathspec_match_diff( /* if every pattern failed to match, then we have failed */ if ((flags & GIT_PATHSPEC_NO_MATCH_ERROR) != 0 && !found_deltas) { - giterr_set(GITERR_INVALID, "no matching deltas were found"); + git_error_set(GIT_ERROR_INVALID, "no matching deltas were found"); error = GIT_ENOTFOUND; } diff --git a/src/posix.c b/src/posix.c index 6e7985ece..bffe02e05 100644 --- a/src/posix.c +++ b/src/posix.c @@ -243,17 +243,17 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs out->len = 0; if ((prot & GIT_PROT_WRITE) && ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)) { - giterr_set(GITERR_OS, "trying to map shared-writeable"); + git_error_set(GIT_ERROR_OS, "trying to map shared-writeable"); return -1; } out->data = malloc(len); - GITERR_CHECK_ALLOC(out->data); + GIT_ERROR_CHECK_ALLOC(out->data); if (!git__is_ssizet(len) || (p_lseek(fd, offset, SEEK_SET) < 0) || (p_read(fd, out->data, len) != (ssize_t)len)) { - giterr_set(GITERR_OS, "mmap emulation failed"); + git_error_set(GIT_ERROR_OS, "mmap emulation failed"); return -1; } diff --git a/src/proxy.c b/src/proxy.c index 9bc2c7fb1..d02558623 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -26,7 +26,7 @@ int git_proxy_options_dup(git_proxy_options *tgt, const git_proxy_options *src) memcpy(tgt, src, sizeof(git_proxy_options)); if (src->url) { tgt->url = git__strdup(src->url); - GITERR_CHECK_ALLOC(tgt->url); + GIT_ERROR_CHECK_ALLOC(tgt->url); } return 0; diff --git a/src/push.c b/src/push.c index 0ba4d9830..9d09e18bb 100644 --- a/src/push.c +++ b/src/push.c @@ -36,7 +36,7 @@ int git_push_new(git_push **out, git_remote *remote) *out = NULL; p = git__calloc(1, sizeof(*p)); - GITERR_CHECK_ALLOC(p); + GIT_ERROR_CHECK_ALLOC(p); p->repo = remote->repo; p->remote = remote; @@ -70,7 +70,7 @@ int git_push_set_options(git_push *push, const git_push_options *opts) if (!push || !opts) return -1; - GITERR_CHECK_VERSION(opts, GIT_PUSH_OPTIONS_VERSION, "git_push_options"); + GIT_ERROR_CHECK_VERSION(opts, GIT_PUSH_OPTIONS_VERSION, "git_push_options"); push->pb_parallelism = opts->pb_parallelism; push->connection.custom_headers = &opts->custom_headers; @@ -91,7 +91,7 @@ static void free_refspec(push_spec *spec) static int check_rref(char *ref) { if (git__prefixcmp(ref, "refs/")) { - giterr_set(GITERR_INVALID, "not a valid reference '%s'", ref); + git_error_set(GIT_ERROR_INVALID, "not a valid reference '%s'", ref); return -1; } @@ -109,10 +109,10 @@ static int check_lref(git_push *push, char *ref) return 0; if (error == GIT_ENOTFOUND) - giterr_set(GITERR_REFERENCE, + git_error_set(GIT_ERROR_REFERENCE, "src refspec '%s' does not match any existing object", ref); else - giterr_set(GITERR_INVALID, "not a valid reference '%s'", ref); + git_error_set(GIT_ERROR_INVALID, "not a valid reference '%s'", ref); return -1; } @@ -123,10 +123,10 @@ static int parse_refspec(git_push *push, push_spec **spec, const char *str) *spec = NULL; s = git__calloc(1, sizeof(*s)); - GITERR_CHECK_ALLOC(s); + GIT_ERROR_CHECK_ALLOC(s); if (git_refspec__parse(&s->refspec, str, false) < 0) { - giterr_set(GITERR_INVALID, "invalid refspec %s", str); + git_error_set(GIT_ERROR_INVALID, "invalid refspec %s", str); goto on_error; } @@ -213,7 +213,7 @@ int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks) if (error != GIT_ENOTFOUND) goto on_error; - giterr_clear(); + git_error_clear(); fire_callback = 0; } @@ -323,7 +323,7 @@ static int queue_objects(git_push *push) continue; if (!git_odb_exists(push->repo->_odb, &spec->roid)) { - giterr_set(GITERR_REFERENCE, + git_error_set(GIT_ERROR_REFERENCE, "cannot push because a reference that you are trying to update on the remote contains commits that are not present locally."); error = GIT_ENONFASTFORWARD; goto on_error; @@ -334,7 +334,7 @@ static int queue_objects(git_push *push) if (error == GIT_ENOTFOUND || (!error && !git_oid_equal(&base, &spec->roid))) { - giterr_set(GITERR_REFERENCE, + git_error_set(GIT_ERROR_REFERENCE, "cannot push non-fastforwardable reference"); error = GIT_ENONFASTFORWARD; goto on_error; @@ -363,13 +363,13 @@ on_error: static int add_update(git_push *push, push_spec *spec) { git_push_update *u = git__calloc(1, sizeof(git_push_update)); - GITERR_CHECK_ALLOC(u); + GIT_ERROR_CHECK_ALLOC(u); u->src_refname = git__strdup(spec->refspec.src); - GITERR_CHECK_ALLOC(u->src_refname); + GIT_ERROR_CHECK_ALLOC(u->src_refname); u->dst_refname = git__strdup(spec->refspec.dst); - GITERR_CHECK_ALLOC(u->dst_refname); + GIT_ERROR_CHECK_ALLOC(u->dst_refname); git_oid_cpy(&u->src, &spec->roid); git_oid_cpy(&u->dst, &spec->loid); @@ -390,7 +390,7 @@ static int calculate_work(git_push *push) /* This is a create or update. Local ref must exist. */ if (git_reference_name_to_id( &spec->loid, push->repo, spec->refspec.src) < 0) { - giterr_set(GITERR_REFERENCE, "no such reference '%s'", spec->refspec.src); + git_error_set(GIT_ERROR_REFERENCE, "no such reference '%s'", spec->refspec.src); return -1; } } @@ -416,7 +416,7 @@ static int do_push(git_push *push, const git_remote_callbacks *callbacks) git_transport *transport = push->remote->transport; if (!transport->push) { - giterr_set(GITERR_NET, "remote transport doesn't support push"); + git_error_set(GIT_ERROR_NET, "remote transport doesn't support push"); error = -1; goto on_error; } @@ -485,7 +485,7 @@ int git_push_finish(git_push *push, const git_remote_callbacks *callbacks) if (!push->unpack_ok) { error = -1; - giterr_set(GITERR_NET, "unpacking the sent packfile failed on the remote"); + git_error_set(GIT_ERROR_NET, "unpacking the sent packfile failed on the remote"); } return error; @@ -501,7 +501,7 @@ int git_push_status_foreach(git_push *push, git_vector_foreach(&push->status, i, status) { int error = cb(status->ref, status->msg, data); if (error) - return giterr_set_after_callback(error); + return git_error_set_after_callback(error); } return 0; diff --git a/src/reader.c b/src/reader.c index d819bb495..c374c4687 100644 --- a/src/reader.c +++ b/src/reader.c @@ -58,7 +58,7 @@ int git_reader_for_tree(git_reader **out, git_tree *tree) assert(out && tree); reader = git__calloc(1, sizeof(tree_reader)); - GITERR_CHECK_ALLOC(reader); + GIT_ERROR_CHECK_ALLOC(reader); reader->reader.read = tree_reader_read; reader->tree = tree; @@ -99,7 +99,7 @@ static int workdir_reader_read( if (error == -1 && errno == ENOENT) error = GIT_ENOTFOUND; - giterr_set(GITERR_OS, "could not stat '%s'", path.ptr); + git_error_set(GIT_ERROR_OS, "could not stat '%s'", path.ptr); goto done; } @@ -155,7 +155,7 @@ int git_reader_for_workdir( assert(out && repo); reader = git__calloc(1, sizeof(workdir_reader)); - GITERR_CHECK_ALLOC(reader); + GIT_ERROR_CHECK_ALLOC(reader); reader->reader.read = workdir_reader_read; reader->repo = repo; @@ -220,7 +220,7 @@ int git_reader_for_index( assert(out && repo); reader = git__calloc(1, sizeof(index_reader)); - GITERR_CHECK_ALLOC(reader); + GIT_ERROR_CHECK_ALLOC(reader); reader->reader.read = index_reader_read; reader->repo = repo; diff --git a/src/rebase.c b/src/rebase.c index 0846487f9..45460367e 100644 --- a/src/rebase.c +++ b/src/rebase.c @@ -153,7 +153,7 @@ GIT_INLINE(int) rebase_readint( return error; if (git__strntol32(&num, asc_out->ptr, asc_out->size, &eol, 10) < 0 || num < 0 || *eol) { - giterr_set(GITERR_REBASE, "the file '%s' contains an invalid numeric value", filename); + git_error_set(GIT_ERROR_REBASE, "the file '%s' contains an invalid numeric value", filename); return -1; } @@ -171,7 +171,7 @@ GIT_INLINE(int) rebase_readoid( return error; if (str_out->size != GIT_OID_HEXSZ || git_oid_fromstr(out, str_out->ptr) < 0) { - giterr_set(GITERR_REBASE, "the file '%s' contains an invalid object ID", filename); + git_error_set(GIT_ERROR_REBASE, "the file '%s' contains an invalid object ID", filename); return -1; } @@ -231,7 +231,7 @@ static int rebase_open_merge(git_rebase *rebase) /* Read cmt.* */ git_array_init_to_size(rebase->operations, end); - GITERR_CHECK_ARRAY(rebase->operations); + GIT_ERROR_CHECK_ARRAY(rebase->operations); for (i = 0; i < end; i++) { git_buf_clear(&cmt); @@ -241,7 +241,7 @@ static int rebase_open_merge(git_rebase *rebase) goto done; operation = rebase_operation_alloc(rebase, GIT_REBASE_OPERATION_PICK, &id, NULL); - GITERR_CHECK_ALLOC(operation); + GIT_ERROR_CHECK_ALLOC(operation); } /* Read 'onto_name' */ @@ -261,7 +261,7 @@ done: static int rebase_alloc(git_rebase **out, const git_rebase_options *rebase_opts) { git_rebase *rebase = git__calloc(1, sizeof(git_rebase)); - GITERR_CHECK_ALLOC(rebase); + GIT_ERROR_CHECK_ALLOC(rebase); *out = NULL; @@ -272,7 +272,7 @@ static int rebase_alloc(git_rebase **out, const git_rebase_options *rebase_opts) if (rebase_opts && rebase_opts->rewrite_notes_ref) { rebase->options.rewrite_notes_ref = git__strdup(rebase_opts->rewrite_notes_ref); - GITERR_CHECK_ALLOC(rebase->options.rewrite_notes_ref); + GIT_ERROR_CHECK_ALLOC(rebase->options.rewrite_notes_ref); } *out = rebase; @@ -282,10 +282,10 @@ static int rebase_alloc(git_rebase **out, const git_rebase_options *rebase_opts) static int rebase_check_versions(const git_rebase_options *given_opts) { - GITERR_CHECK_VERSION(given_opts, GIT_REBASE_OPTIONS_VERSION, "git_rebase_options"); + GIT_ERROR_CHECK_VERSION(given_opts, GIT_REBASE_OPTIONS_VERSION, "git_rebase_options"); if (given_opts) - GITERR_CHECK_VERSION(&given_opts->checkout_options, GIT_CHECKOUT_OPTIONS_VERSION, "git_checkout_options"); + GIT_ERROR_CHECK_VERSION(&given_opts->checkout_options, GIT_CHECKOUT_OPTIONS_VERSION, "git_checkout_options"); return 0; } @@ -314,7 +314,7 @@ int git_rebase_open( goto done; if (rebase->type == GIT_REBASE_TYPE_NONE) { - giterr_set(GITERR_REBASE, "there is no rebase in progress"); + git_error_set(GIT_ERROR_REBASE, "there is no rebase in progress"); error = GIT_ENOTFOUND; goto done; } @@ -370,14 +370,14 @@ int git_rebase_open( switch (rebase->type) { case GIT_REBASE_TYPE_INTERACTIVE: - giterr_set(GITERR_REBASE, "interactive rebase is not supported"); + git_error_set(GIT_ERROR_REBASE, "interactive rebase is not supported"); error = -1; break; case GIT_REBASE_TYPE_MERGE: error = rebase_open_merge(rebase); break; case GIT_REBASE_TYPE_APPLY: - giterr_set(GITERR_REBASE, "patch application rebase is not supported"); + git_error_set(GIT_ERROR_REBASE, "patch application rebase is not supported"); error = -1; break; default: @@ -476,7 +476,7 @@ static int rebase_setupfiles(git_rebase *rebase) git_oid_fmt(orig_head, &rebase->orig_head_id); if (p_mkdir(rebase->state_path, REBASE_DIR_MODE) < 0) { - giterr_set(GITERR_OS, "failed to create rebase directory '%s'", rebase->state_path); + git_error_set(GIT_ERROR_OS, "failed to create rebase directory '%s'", rebase->state_path); return -1; } @@ -509,7 +509,7 @@ static int rebase_ensure_not_in_progress(git_repository *repo) return error; if (type != GIT_REBASE_TYPE_NONE) { - giterr_set(GITERR_REBASE, "there is an existing rebase in progress"); + git_error_set(GIT_ERROR_REBASE, "there is an existing rebase in progress"); return -1; } @@ -534,7 +534,7 @@ static int rebase_ensure_not_dirty( goto done; if (git_diff_num_deltas(diff) > 0) { - giterr_set(GITERR_REBASE, "uncommitted changes exist in index"); + git_error_set(GIT_ERROR_REBASE, "uncommitted changes exist in index"); error = fail_with; goto done; } @@ -550,7 +550,7 @@ static int rebase_ensure_not_dirty( goto done; if (git_diff_num_deltas(diff) > 0) { - giterr_set(GITERR_REBASE, "unstaged changes exist in workdir"); + git_error_set(GIT_ERROR_REBASE, "unstaged changes exist in workdir"); error = fail_with; goto done; } @@ -599,7 +599,7 @@ static int rebase_init_operations( continue; operation = rebase_operation_alloc(rebase, GIT_REBASE_OPERATION_PICK, &id, NULL); - GITERR_CHECK_ALLOC(operation); + GIT_ERROR_CHECK_ALLOC(operation); } error = 0; @@ -628,17 +628,17 @@ static int rebase_init_merge( goto done; rebase->state_path = git_buf_detach(&state_path); - GITERR_CHECK_ALLOC(rebase->state_path); + GIT_ERROR_CHECK_ALLOC(rebase->state_path); if (branch->ref_name && strcmp(branch->ref_name, "HEAD")) { rebase->orig_head_name = git__strdup(branch->ref_name); - GITERR_CHECK_ALLOC(rebase->orig_head_name); + GIT_ERROR_CHECK_ALLOC(rebase->orig_head_name); } else { rebase->head_detached = 1; } rebase->onto_name = git__strdup(rebase_onto_name(onto)); - GITERR_CHECK_ALLOC(rebase->onto_name); + GIT_ERROR_CHECK_ALLOC(rebase->onto_name); rebase->quiet = rebase->options.quiet; @@ -807,7 +807,7 @@ static int rebase_next_merge( goto done; if ((parent_count = git_commit_parentcount(current_commit)) > 1) { - giterr_set(GITERR_REBASE, "cannot rebase a merge commit"); + git_error_set(GIT_ERROR_REBASE, "cannot rebase a merge commit"); error = -1; goto done; } else if (parent_count) { @@ -864,7 +864,7 @@ static int rebase_next_inmemory( goto done; if ((parent_count = git_commit_parentcount(current_commit)) > 1) { - giterr_set(GITERR_REBASE, "cannot rebase a merge commit"); + git_error_set(GIT_ERROR_REBASE, "cannot rebase a merge commit"); error = -1; goto done; } else if (parent_count) { @@ -950,7 +950,7 @@ static int rebase_commit__create( operation = git_array_get(rebase->operations, rebase->current); if (git_index_has_conflicts(index)) { - giterr_set(GITERR_REBASE, "conflicts have not been resolved"); + git_error_set(GIT_ERROR_REBASE, "conflicts have not been resolved"); error = GIT_EUNMERGED; goto done; } @@ -962,7 +962,7 @@ static int rebase_commit__create( goto done; if (git_oid_equal(&tree_id, git_tree_id(parent_tree))) { - giterr_set(GITERR_REBASE, "this patch has already been applied"); + git_error_set(GIT_ERROR_REBASE, "this patch has already been applied"); error = GIT_EAPPLIED; goto done; } @@ -1148,7 +1148,7 @@ static int notes_ref_lookup(git_buf *out, git_rebase *rebase) if (error != GIT_ENOTFOUND) goto done; - giterr_clear(); + git_error_clear(); do_rewrite = 1; } @@ -1175,7 +1175,7 @@ static int rebase_copy_note( if ((error = git_note_read(¬e, rebase->repo, notes_ref, from)) < 0) { if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = 0; } @@ -1188,7 +1188,7 @@ static int rebase_copy_note( (error = git_signature_now(&who, "unknown", "unknown")) < 0) goto done; - giterr_clear(); + git_error_clear(); } committer = who; @@ -1216,7 +1216,7 @@ static int rebase_copy_notes( if ((error = notes_ref_lookup(¬es_ref, rebase)) < 0) { if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = 0; } @@ -1259,7 +1259,7 @@ static int rebase_copy_notes( goto done; on_error: - giterr_set(GITERR_REBASE, "invalid rewritten file at line %d", linenum); + git_error_set(GIT_ERROR_REBASE, "invalid rewritten file at line %d", linenum); error = -1; done: diff --git a/src/refdb.c b/src/refdb.c index c162a153f..b466153a7 100644 --- a/src/refdb.c +++ b/src/refdb.c @@ -24,7 +24,7 @@ int git_refdb_new(git_refdb **out, git_repository *repo) assert(out && repo); db = git__calloc(1, sizeof(*db)); - GITERR_CHECK_ALLOC(db); + GIT_ERROR_CHECK_ALLOC(db); db->repo = repo; @@ -127,7 +127,7 @@ int git_refdb_iterator(git_reference_iterator **out, git_refdb *db, const char * int error; if (!db->backend || !db->backend->iterator) { - giterr_set(GITERR_REFERENCE, "this backend doesn't support iterators"); + git_error_set(GIT_ERROR_REFERENCE, "this backend doesn't support iterators"); return -1; } @@ -245,7 +245,7 @@ int git_refdb_lock(void **payload, git_refdb *db, const char *refname) assert(payload && db && refname); if (!db->backend->lock) { - giterr_set(GITERR_REFERENCE, "backend does not support locking"); + git_error_set(GIT_ERROR_REFERENCE, "backend does not support locking"); return -1; } diff --git a/src/refdb_fs.c b/src/refdb_fs.c index 361451b7d..d582cb8a2 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -94,7 +94,7 @@ static int packed_reload(refdb_fs_backend *backend) if (error <= 0) { if (error == GIT_ENOTFOUND) { git_sortedcache_clear(backend->refcache, true); - giterr_clear(); + git_error_clear(); error = 0; } return error; @@ -188,7 +188,7 @@ static int packed_reload(refdb_fs_backend *backend) return 0; parse_failed: - giterr_set(GITERR_REFERENCE, "corrupted packed references file"); + git_error_set(GIT_ERROR_REFERENCE, "corrupted packed references file"); git_sortedcache_clear(backend->refcache, false); git_sortedcache_wunlock(backend->refcache); @@ -215,7 +215,7 @@ static int loose_parse_oid( return 0; corrupted: - giterr_set(GITERR_REFERENCE, "corrupted loose reference file: %s", filename); + git_error_set(GIT_ERROR_REFERENCE, "corrupted loose reference file: %s", filename); return -1; } @@ -242,7 +242,7 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name) * the filesystem under us and skip it... */ if (loose_readbuffer(&ref_file, backend->gitpath, name) < 0) { - giterr_clear(); + git_error_clear(); goto done; } @@ -283,7 +283,7 @@ static int _dirent_loose_load(void *payload, git_buf *full_path) full_path, backend->direach_flags, _dirent_loose_load, backend); /* Race with the filesystem, ignore it */ if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); return 0; } @@ -352,7 +352,7 @@ static const char *loose_parse_symbolic(git_buf *file_content) refname_start = (const char *)file_content->ptr; if (git_buf_len(file_content) < header_len + 1) { - giterr_set(GITERR_REFERENCE, "corrupted loose reference file"); + git_error_set(GIT_ERROR_REFERENCE, "corrupted loose reference file"); return NULL; } @@ -420,7 +420,7 @@ static int loose_lookup( static int ref_error_notfound(const char *name) { - giterr_set(GITERR_REFERENCE, "reference '%s' not found", name); + git_error_set(GIT_ERROR_REFERENCE, "reference '%s' not found", name); return GIT_ENOTFOUND; } @@ -468,7 +468,7 @@ static int refdb_fs_backend__lookup( /* only try to lookup this reference on the packfile if it * wasn't found on the loose refs; not if there was a critical error */ if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = packed_lookup(out, backend, ref_name); } @@ -596,7 +596,7 @@ static int refdb_fs_backend__iterator_next( if (loose_lookup(out, backend, path) == 0) return 0; - giterr_clear(); + git_error_clear(); } if (!iter->cache) { @@ -639,7 +639,7 @@ static int refdb_fs_backend__iterator_next_name( return 0; } - giterr_clear(); + git_error_clear(); } if (!iter->cache) { @@ -679,7 +679,7 @@ static int refdb_fs_backend__iterator( return error; iter = git__calloc(1, sizeof(refdb_fs_iter)); - GITERR_CHECK_ALLOC(iter); + GIT_ERROR_CHECK_ALLOC(iter); git_pool_init(&iter->pool, 1); @@ -743,7 +743,7 @@ static int reference_path_available( } if (exists) { - giterr_set(GITERR_REFERENCE, + git_error_set(GIT_ERROR_REFERENCE, "failed to write reference '%s': a reference with " "that name already exists.", new_ref); return GIT_EEXISTS; @@ -757,7 +757,7 @@ static int reference_path_available( if (ref && !ref_is_available(old_ref, new_ref, ref->name)) { git_sortedcache_runlock(backend->refcache); - giterr_set(GITERR_REFERENCE, + git_error_set(GIT_ERROR_REFERENCE, "path to reference '%s' collides with existing one", new_ref); return -1; } @@ -776,7 +776,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char * assert(file && backend && name); if (!git_path_isvalid(backend->repo, name, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) { - giterr_set(GITERR_INVALID, "invalid reference name '%s'", name); + git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", name); return GIT_EINVALIDSPEC; } @@ -801,7 +801,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char * error = git_filebuf_open(file, ref_path.ptr, filebuf_flags, GIT_REFS_FILE_MODE); if (error == GIT_EDIRECTORY) - giterr_set(GITERR_REFERENCE, "cannot lock ref '%s', there are refs beneath that folder", name); + git_error_set(GIT_ERROR_REFERENCE, "cannot lock ref '%s', there are refs beneath that folder", name); git_buf_dispose(&ref_path); return error; @@ -832,7 +832,7 @@ static int refdb_fs_backend__lock(void **out, git_refdb_backend *_backend, const refdb_fs_backend *backend = (refdb_fs_backend *) _backend; lock = git__calloc(1, sizeof(git_filebuf)); - GITERR_CHECK_ALLOC(lock); + GIT_ERROR_CHECK_ALLOC(lock); if ((error = loose_lock(lock, backend, refname)) < 0) { git__free(lock); @@ -991,7 +991,7 @@ static int packed_remove_loose(refdb_fs_backend *backend) if (error < 0) { git_buf_dispose(&ref_content); - giterr_set(GITERR_REFERENCE, "failed to lock loose reference '%s'", ref->name); + git_error_set(GIT_ERROR_REFERENCE, "failed to lock loose reference '%s'", ref->name); return error; } @@ -1274,7 +1274,7 @@ static int refdb_fs_backend__write_tail( goto on_error; if (cmp) { - giterr_set(GITERR_REFERENCE, "old reference value does not match"); + git_error_set(GIT_ERROR_REFERENCE, "old reference value does not match"); error = GIT_EMODIFIED; goto on_error; } @@ -1389,7 +1389,7 @@ static int refdb_fs_backend__delete_tail( goto cleanup; if (cmp) { - giterr_set(GITERR_REFERENCE, "old reference value does not match"); + git_error_set(GIT_ERROR_REFERENCE, "old reference value does not match"); error = GIT_EMODIFIED; goto cleanup; } @@ -1579,10 +1579,10 @@ static int reflog_alloc(git_reflog **reflog, const char *name) *reflog = NULL; log = git__calloc(1, sizeof(git_reflog)); - GITERR_CHECK_ALLOC(log); + GIT_ERROR_CHECK_ALLOC(log); log->ref_name = git__strdup(name); - GITERR_CHECK_ALLOC(log->ref_name); + GIT_ERROR_CHECK_ALLOC(log->ref_name); if (git_vector_init(&log->entries, 0, NULL) < 0) { git__free(log->ref_name); @@ -1602,7 +1602,7 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size) #define seek_forward(_increase) do { \ if (_increase >= buf_size) { \ - giterr_set(GITERR_INVALID, "ran out of data while parsing reflog"); \ + git_error_set(GIT_ERROR_INVALID, "ran out of data while parsing reflog"); \ goto fail; \ } \ buf += _increase; \ @@ -1611,10 +1611,10 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size) while (buf_size > GIT_REFLOG_SIZE_MIN) { entry = git__calloc(1, sizeof(git_reflog_entry)); - GITERR_CHECK_ALLOC(entry); + GIT_ERROR_CHECK_ALLOC(entry); entry->committer = git__calloc(1, sizeof(git_signature)); - GITERR_CHECK_ALLOC(entry->committer); + GIT_ERROR_CHECK_ALLOC(entry->committer); if (git_oid_fromstrn(&entry->oid_old, buf, GIT_OID_HEXSZ) < 0) goto fail; @@ -1642,7 +1642,7 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size) seek_forward(1); entry->msg = git__strndup(ptr, buf - ptr); - GITERR_CHECK_ALLOC(entry->msg); + GIT_ERROR_CHECK_ALLOC(entry->msg); } else entry->msg = NULL; @@ -1820,7 +1820,7 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char repo = backend->repo; if (!git_path_isvalid(backend->repo, refname, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) { - giterr_set(GITERR_INVALID, "invalid reference name '%s'", refname); + git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", refname); return GIT_EINVALIDSPEC; } @@ -1828,7 +1828,7 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char return -1; if (!git_path_isfile(git_buf_cstr(&log_path))) { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "log file for reference '%s' doesn't exist", refname); error = -1; goto cleanup; @@ -1917,7 +1917,7 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co if (error == GIT_ENOTFOUND) return 0; - giterr_clear(); + git_error_clear(); } } @@ -1940,7 +1940,7 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co if (error == GIT_ENOTFOUND) error = 0; } else if (git_path_isdir(git_buf_cstr(&path))) { - giterr_set(GITERR_REFERENCE, "cannot create reflog at '%s', there are reflogs beneath that folder", + git_error_set(GIT_ERROR_REFERENCE, "cannot create reflog at '%s', there are reflogs beneath that folder", ref->name); error = GIT_EDIRECTORY; } @@ -2014,7 +2014,7 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_ p_close(fd); if (p_rename(git_buf_cstr(&old_path), git_buf_cstr(&temp_path)) < 0) { - giterr_set(GITERR_OS, "failed to rename reflog for %s", new_name); + git_error_set(GIT_ERROR_OS, "failed to rename reflog for %s", new_name); error = -1; goto cleanup; } @@ -2031,7 +2031,7 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_ } if (p_rename(git_buf_cstr(&temp_path), git_buf_cstr(&new_path)) < 0) { - giterr_set(GITERR_OS, "failed to rename reflog for %s", new_name); + git_error_set(GIT_ERROR_OS, "failed to rename reflog for %s", new_name); error = -1; } @@ -2078,7 +2078,7 @@ int git_refdb_backend_fs( refdb_fs_backend *backend; backend = git__calloc(1, sizeof(refdb_fs_backend)); - GITERR_CHECK_ALLOC(backend); + GIT_ERROR_CHECK_ALLOC(backend); backend->repo = repository; diff --git a/src/reflog.c b/src/reflog.c index 938999218..1834a2736 100644 --- a/src/reflog.c +++ b/src/reflog.c @@ -81,7 +81,7 @@ int git_reflog_append(git_reflog *reflog, const git_oid *new_oid, const git_sign assert(reflog && new_oid && committer); entry = git__calloc(1, sizeof(git_reflog_entry)); - GITERR_CHECK_ALLOC(entry); + GIT_ERROR_CHECK_ALLOC(entry); if ((git_signature_dup(&entry->committer, committer)) < 0) goto cleanup; @@ -94,7 +94,7 @@ int git_reflog_append(git_reflog *reflog, const git_oid *new_oid, const git_sign if (newline) { if (newline[1] != '\0') { - giterr_set(GITERR_INVALID, "reflog message cannot contain newline"); + git_error_set(GIT_ERROR_INVALID, "reflog message cannot contain newline"); goto cleanup; } @@ -194,7 +194,7 @@ int git_reflog_drop(git_reflog *reflog, size_t idx, int rewrite_previous_entry) entry = (git_reflog_entry *)git_reflog_entry_byindex(reflog, idx); if (entry == NULL) { - giterr_set(GITERR_REFERENCE, "no reflog entry at index %"PRIuZ, idx); + git_error_set(GIT_ERROR_REFERENCE, "no reflog entry at index %"PRIuZ, idx); return GIT_ENOTFOUND; } diff --git a/src/refs.c b/src/refs.c index 6e919b2fc..644bc2e68 100644 --- a/src/refs.c +++ b/src/refs.c @@ -113,7 +113,7 @@ int git_reference_dup(git_reference **dest, git_reference *source) else *dest = git_reference__alloc(source->name, &source->target.oid, &source->peel); - GITERR_CHECK_ALLOC(*dest); + GIT_ERROR_CHECK_ALLOC(*dest); (*dest)->db = source->db; GIT_REFCOUNT_INC((*dest)->db); @@ -243,7 +243,7 @@ int git_reference_lookup_resolved( } if (scan_type != GIT_REFERENCE_DIRECT && max_nesting != 0) { - giterr_set(GITERR_REFERENCE, + git_error_set(GIT_ERROR_REFERENCE, "cannot resolve reference (>%u levels deep)", max_nesting); git_reference_free(ref); return -1; @@ -339,12 +339,12 @@ int git_reference_dwim(git_reference **out, git_repository *repo, const char *re cleanup: if (error && !foundvalid) { /* never found a valid reference name */ - giterr_set(GITERR_REFERENCE, + git_error_set(GIT_ERROR_REFERENCE, "could not use '%s' as valid reference name", git_buf_cstr(&name)); } if (error == GIT_ENOTFOUND) - giterr_set(GITERR_REFERENCE, "no reference found for shorthand '%s'", refname); + git_error_set(GIT_ERROR_REFERENCE, "no reference found for shorthand '%s'", refname); git_buf_dispose(&name); git_buf_dispose(&refnamebuf); @@ -437,7 +437,7 @@ static int reference__create( assert(symbolic == NULL); if (!git_object__is_valid(repo, oid, GIT_OBJECT_ANY)) { - giterr_set(GITERR_REFERENCE, + git_error_set(GIT_ERROR_REFERENCE, "target OID for the reference doesn't exist on the repository"); return -1; } @@ -455,7 +455,7 @@ static int reference__create( ref = git_reference__alloc_symbolic(normalized, normalized_target); } - GITERR_CHECK_ALLOC(ref); + GIT_ERROR_CHECK_ALLOC(ref); if ((error = git_refdb_write(refdb, ref, force, signature, log_message, old_id, old_target)) < 0) { git_reference_free(ref); @@ -569,7 +569,7 @@ static int ensure_is_an_updatable_direct_reference(git_reference *ref) if (ref->type == GIT_REFERENCE_DIRECT) return 0; - giterr_set(GITERR_REFERENCE, "cannot set OID on symbolic reference"); + git_error_set(GIT_ERROR_REFERENCE, "cannot set OID on symbolic reference"); return -1; } @@ -597,7 +597,7 @@ static int ensure_is_an_updatable_symbolic_reference(git_reference *ref) if (ref->type == GIT_REFERENCE_SYMBOLIC) return 0; - giterr_set(GITERR_REFERENCE, "cannot set symbolic target on a direct reference"); + git_error_set(GIT_ERROR_REFERENCE, "cannot set symbolic target on a direct reference"); return -1; } @@ -631,7 +631,7 @@ static int update_wt_heads(git_repository *repo, const char *path, void *payload int error; if ((error = git_reference__read_head(&head, repo, path)) < 0) { - giterr_set(GITERR_REFERENCE, "could not read HEAD when renaming references"); + git_error_set(GIT_ERROR_REFERENCE, "could not read HEAD when renaming references"); goto out; } @@ -648,7 +648,7 @@ static int update_wt_heads(git_repository *repo, const char *path, void *payload /* Update HEAD it was pointing to the reference being renamed */ if ((error = git_repository_create_head(gitdir, data->new_name)) < 0) { - giterr_set(GITERR_REFERENCE, "failed to update HEAD after renaming reference"); + git_error_set(GIT_ERROR_REFERENCE, "failed to update HEAD after renaming reference"); goto out; } @@ -730,7 +730,7 @@ int git_reference_resolve(git_reference **ref_out, const git_reference *ref) return git_reference_lookup_resolved(ref_out, ref->db->repo, ref->target.symbolic, -1); default: - giterr_set(GITERR_REFERENCE, "invalid reference"); + git_error_set(GIT_ERROR_REFERENCE, "invalid reference"); return -1; } } @@ -749,7 +749,7 @@ int git_reference_foreach( while (!(error = git_reference_next(&ref, iter))) { if ((error = callback(ref, payload)) != 0) { - giterr_set_after_callback(error); + git_error_set_after_callback(error); break; } } @@ -775,7 +775,7 @@ int git_reference_foreach_name( while (!(error = git_reference_next_name(&refname, iter))) { if ((error = callback(refname, payload)) != 0) { - giterr_set_after_callback(error); + git_error_set_after_callback(error); break; } } @@ -802,7 +802,7 @@ int git_reference_foreach_glob( while (!(error = git_reference_next_name(&refname, iter))) { if ((error = callback(refname, payload)) != 0) { - giterr_set_after_callback(error); + git_error_set_after_callback(error); break; } } @@ -856,7 +856,7 @@ void git_reference_iterator_free(git_reference_iterator *iter) static int cb__reflist_add(const char *ref, void *data) { char *name = git__strdup(ref); - GITERR_CHECK_ALLOC(name); + GIT_ERROR_CHECK_ALLOC(name); return git_vector_insert((git_vector *)data, name); } @@ -1073,8 +1073,8 @@ int git_reference__normalize_name( cleanup: if (error == GIT_EINVALIDSPEC) - giterr_set( - GITERR_REFERENCE, + git_error_set( + GIT_ERROR_REFERENCE, "the given reference name '%s' is not valid", name); if (error && normalize) @@ -1100,8 +1100,8 @@ int git_reference_normalize_name( goto cleanup; if (git_buf_len(&buf) > buffer_size - 1) { - giterr_set( - GITERR_REFERENCE, + git_error_set( + GIT_ERROR_REFERENCE, "the provided buffer is too short to hold the normalization of '%s'", name); error = GIT_EBUFS; goto cleanup; @@ -1148,7 +1148,7 @@ static int get_terminal(git_reference **out, git_repository *repo, const char *r int error = 0; if (nesting > MAX_NESTING_LEVEL) { - giterr_set(GITERR_REFERENCE, "reference chain too deep (%d)", nesting); + git_error_set(GIT_ERROR_REFERENCE, "reference chain too deep (%d)", nesting); return GIT_ENOTFOUND; } @@ -1198,11 +1198,11 @@ int git_reference__update_terminal( /* found a dangling symref */ if (error == GIT_ENOTFOUND && ref) { assert(git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC); - giterr_clear(); + git_error_clear(); error = reference__create(&ref2, repo, ref->target.symbolic, oid, NULL, 0, to_use, log_message, NULL, NULL); } else if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = reference__create(&ref2, repo, ref_name, oid, NULL, 0, to_use, log_message, NULL, NULL); } else if (error == 0) { @@ -1341,8 +1341,8 @@ int git_reference_is_note(const git_reference *ref) static int peel_error(int error, const git_reference *ref, const char* msg) { - giterr_set( - GITERR_INVALID, + git_error_set( + GIT_ERROR_INVALID, "the reference '%s' cannot be peeled - %s", git_reference_name(ref), msg); return error; } @@ -1402,7 +1402,7 @@ cleanup: int git_reference__is_valid_name(const char *refname, unsigned int flags) { if (git_reference__normalize_name(NULL, refname, flags) < 0) { - giterr_clear(); + git_error_clear(); return false; } diff --git a/src/refspec.c b/src/refspec.c index 7e68071d9..eaf0c2c83 100644 --- a/src/refspec.c +++ b/src/refspec.c @@ -43,11 +43,11 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch) if (!is_fetch && rhs == lhs && rhs[1] == '\0') { refspec->matching = 1; refspec->string = git__strdup(input); - GITERR_CHECK_ALLOC(refspec->string); + GIT_ERROR_CHECK_ALLOC(refspec->string); refspec->src = git__strdup(""); - GITERR_CHECK_ALLOC(refspec->src); + GIT_ERROR_CHECK_ALLOC(refspec->src); refspec->dst = git__strdup(""); - GITERR_CHECK_ALLOC(refspec->dst); + GIT_ERROR_CHECK_ALLOC(refspec->dst); return 0; } @@ -132,18 +132,18 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch) /* if the RHS is empty, then it's a copy of the LHS */ if (!refspec->dst) { refspec->dst = git__strdup(refspec->src); - GITERR_CHECK_ALLOC(refspec->dst); + GIT_ERROR_CHECK_ALLOC(refspec->dst); } } refspec->string = git__strdup(input); - GITERR_CHECK_ALLOC(refspec->string); + GIT_ERROR_CHECK_ALLOC(refspec->string); return 0; invalid: - giterr_set( - GITERR_INVALID, + git_error_set( + GIT_ERROR_INVALID, "'%s' is not a valid refspec.", input); git_refspec__dispose(refspec); return -1; @@ -169,7 +169,7 @@ int git_refspec_parse(git_refspec **out_refspec, const char *input, int is_fetch *out_refspec = NULL; refspec = git__malloc(sizeof(git_refspec)); - GITERR_CHECK_ALLOC(refspec); + GIT_ERROR_CHECK_ALLOC(refspec); if (git_refspec__parse(refspec, input, !!is_fetch) != 0) { git__free(refspec); @@ -273,7 +273,7 @@ int git_refspec_transform(git_buf *out, const git_refspec *spec, const char *nam git_buf_sanitize(out); if (!git_refspec_src_matches(spec, name)) { - giterr_set(GITERR_INVALID, "ref '%s' doesn't match the source", name); + git_error_set(GIT_ERROR_INVALID, "ref '%s' doesn't match the source", name); return -1; } @@ -289,7 +289,7 @@ int git_refspec_rtransform(git_buf *out, const git_refspec *spec, const char *na git_buf_sanitize(out); if (!git_refspec_dst_matches(spec, name)) { - giterr_set(GITERR_INVALID, "ref '%s' doesn't match the destination", name); + git_error_set(GIT_ERROR_INVALID, "ref '%s' doesn't match the destination", name); return -1; } @@ -342,7 +342,7 @@ int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs) assert(out && spec && refs); cur = git__calloc(1, sizeof(git_refspec)); - GITERR_CHECK_ALLOC(cur); + GIT_ERROR_CHECK_ALLOC(cur); cur->force = spec->force; cur->push = spec->push; @@ -355,7 +355,7 @@ int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs) for (j = 0; formatters[j]; j++) { git_buf_clear(&buf); git_buf_printf(&buf, formatters[j], spec->src); - GITERR_CHECK_ALLOC_BUF(&buf); + GIT_ERROR_CHECK_ALLOC_BUF(&buf); key.name = (char *) git_buf_cstr(&buf); if (!git_vector_search(&pos, refs, &key)) { @@ -368,7 +368,7 @@ int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs) /* No shorthands found, copy over the name */ if (cur->src == NULL && spec->src != NULL) { cur->src = git__strdup(spec->src); - GITERR_CHECK_ALLOC(cur->src); + GIT_ERROR_CHECK_ALLOC(cur->src); } if (spec->dst && git__prefixcmp(spec->dst, GIT_REFS_DIR)) { @@ -380,7 +380,7 @@ int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs) } git_buf_puts(&buf, spec->dst); - GITERR_CHECK_ALLOC_BUF(&buf); + GIT_ERROR_CHECK_ALLOC_BUF(&buf); cur->dst = git_buf_detach(&buf); } @@ -389,7 +389,7 @@ int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs) if (cur->dst == NULL && spec->dst != NULL) { cur->dst = git__strdup(spec->dst); - GITERR_CHECK_ALLOC(cur->dst); + GIT_ERROR_CHECK_ALLOC(cur->dst); } return git_vector_insert(out, cur); diff --git a/src/remote.c b/src/remote.c index 2cfb921ba..2f0b8c5ee 100644 --- a/src/remote.c +++ b/src/remote.c @@ -35,7 +35,7 @@ static int add_refspec_to(git_vector *vector, const char *string, bool is_fetch) git_refspec *spec; spec = git__calloc(1, sizeof(git_refspec)); - GITERR_CHECK_ALLOC(spec); + GIT_ERROR_CHECK_ALLOC(spec); if (git_refspec__parse(spec, string, is_fetch) < 0) { git__free(spec); @@ -85,8 +85,8 @@ static int ensure_remote_name_is_valid(const char *name) int error = 0; if (!git_remote_is_valid_name(name)) { - giterr_set( - GITERR_CONFIG, + git_error_set( + GIT_ERROR_CONFIG, "'%s' is not a valid remote name.", name ? name : "(null)"); error = GIT_EINVALIDSPEC; } @@ -111,7 +111,7 @@ static int write_add_refspec(git_repository *repo, const char *name, const char return error; if ((error = git_refspec__parse(&spec, refspec, fetch)) < 0) { - if (giterr_last()->klass != GITERR_NOMEMORY) + if (git_error_last()->klass != GIT_ERROR_NOMEMORY) error = GIT_EINVALIDSPEC; return error; @@ -168,7 +168,7 @@ static int get_check_cert(int *out, git_repository *repo) static int canonicalize_url(git_buf *out, const char *in) { if (in == NULL || strlen(in) == 0) { - giterr_set(GITERR_INVALID, "cannot set empty URL"); + git_error_set(GIT_ERROR_INVALID, "cannot set empty URL"); return GIT_EINVALIDSPEC; } @@ -212,7 +212,7 @@ static int ensure_remote_doesnot_exist(git_repository *repo, const char *name) git_remote_free(remote); - giterr_set(GITERR_CONFIG, "remote '%s' already exists", name); + git_error_set(GIT_ERROR_CONFIG, "remote '%s' already exists", name); return GIT_EEXISTS; } @@ -240,7 +240,7 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem opts = &dummy_opts; } - GITERR_CHECK_VERSION(opts, GIT_REMOTE_CREATE_OPTIONS_VERSION, "git_remote_create_options"); + GIT_ERROR_CHECK_VERSION(opts, GIT_REMOTE_CREATE_OPTIONS_VERSION, "git_remote_create_options"); if (opts->name != NULL) { if ((error = ensure_remote_name_is_valid(opts->name)) < 0) @@ -257,7 +257,7 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem } remote = git__calloc(1, sizeof(git_remote)); - GITERR_CHECK_ALLOC(remote); + GIT_ERROR_CHECK_ALLOC(remote); remote->repo = opts->repository; @@ -270,11 +270,11 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem } else { remote->url = git__strdup(canonical_url.ptr); } - GITERR_CHECK_ALLOC(remote->url); + GIT_ERROR_CHECK_ALLOC(remote->url); if (opts->name != NULL) { remote->name = git__strdup(opts->name); - GITERR_CHECK_ALLOC(remote->name); + GIT_ERROR_CHECK_ALLOC(remote->name); if (opts->repository && ((error = git_buf_printf(&var, CONFIG_URL_FMT, opts->name)) < 0 || @@ -393,21 +393,21 @@ int git_remote_dup(git_remote **dest, git_remote *source) int error = 0; git_refspec *spec; git_remote *remote = git__calloc(1, sizeof(git_remote)); - GITERR_CHECK_ALLOC(remote); + GIT_ERROR_CHECK_ALLOC(remote); if (source->name != NULL) { remote->name = git__strdup(source->name); - GITERR_CHECK_ALLOC(remote->name); + GIT_ERROR_CHECK_ALLOC(remote->name); } if (source->url != NULL) { remote->url = git__strdup(source->url); - GITERR_CHECK_ALLOC(remote->url); + GIT_ERROR_CHECK_ALLOC(remote->url); } if (source->pushurl != NULL) { remote->pushurl = git__strdup(source->pushurl); - GITERR_CHECK_ALLOC(remote->pushurl); + GIT_ERROR_CHECK_ALLOC(remote->pushurl); } remote->repo = source->repo; @@ -466,7 +466,7 @@ static int get_optional_config( *found = !error; if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = 0; } @@ -492,10 +492,10 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name) return error; remote = git__calloc(1, sizeof(git_remote)); - GITERR_CHECK_ALLOC(remote); + GIT_ERROR_CHECK_ALLOC(remote); remote->name = git__strdup(name); - GITERR_CHECK_ALLOC(remote->name); + GIT_ERROR_CHECK_ALLOC(remote->name); if (git_vector_init(&remote->refs, 32, NULL) < 0 || git_vector_init(&remote->refspecs, 2, NULL) < 0 || @@ -518,7 +518,7 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name) if (found && strlen(val) > 0) { remote->url = apply_insteadof(config, val, GIT_DIRECTION_FETCH); - GITERR_CHECK_ALLOC(remote->url); + GIT_ERROR_CHECK_ALLOC(remote->url); } val = NULL; @@ -532,13 +532,13 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name) if (!optional_setting_found) { error = GIT_ENOTFOUND; - giterr_set(GITERR_CONFIG, "remote '%s' does not exist", name); + git_error_set(GIT_ERROR_CONFIG, "remote '%s' does not exist", name); goto cleanup; } if (found && strlen(val) > 0) { remote->pushurl = apply_insteadof(config, val, GIT_DIRECTION_PUSH); - GITERR_CHECK_ALLOC(remote->pushurl); + GIT_ERROR_CHECK_ALLOC(remote->pushurl); } data.remote = remote; @@ -588,11 +588,11 @@ static int lookup_remote_prune_config(git_remote *remote, git_config *config, co if ((error = git_config_get_bool(&remote->prune_refs, config, git_buf_cstr(&buf))) < 0) { if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); if ((error = git_config_get_bool(&remote->prune_refs, config, "fetch.prune")) < 0) { if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = 0; } } @@ -717,20 +717,20 @@ int git_remote__connect(git_remote *remote, git_direction direction, const git_r assert(remote); if (callbacks) { - GITERR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); + GIT_ERROR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); credentials = callbacks->credentials; transport = callbacks->transport; payload = callbacks->payload; } if (conn->proxy) - GITERR_CHECK_VERSION(conn->proxy, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options"); + GIT_ERROR_CHECK_VERSION(conn->proxy, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options"); t = remote->transport; url = git_remote__urlfordirection(remote, direction); if (url == NULL) { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "Malformed remote '%s' - missing %s URL", remote->name ? remote->name : "(anonymous)", direction == GIT_DIRECTION_FETCH ? "fetch" : "push"); @@ -783,7 +783,7 @@ int git_remote_ls(const git_remote_head ***out, size_t *size, git_remote *remote assert(remote); if (!remote->transport) { - giterr_set(GITERR_NET, "this remote has never connected"); + git_error_set(GIT_ERROR_NET, "this remote has never connected"); return -1; } @@ -847,7 +847,7 @@ int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_ur if (error < 0) { if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = 0; } @@ -857,7 +857,7 @@ int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_ur *proxy_url = git_buf_detach(&val); found: - GITERR_CHECK_ALLOC(*proxy_url); + GIT_ERROR_CHECK_ALLOC(*proxy_url); git_config_entry_free(ce); return 0; @@ -929,15 +929,15 @@ int git_remote_download(git_remote *remote, const git_strarray *refspecs, const assert(remote); if (!remote->repo) { - giterr_set(GITERR_INVALID, "cannot download detached remote"); + git_error_set(GIT_ERROR_INVALID, "cannot download detached remote"); return -1; } if (opts) { - GITERR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); + GIT_ERROR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); cbs = &opts->callbacks; custom_headers = &opts->custom_headers; - GITERR_CHECK_VERSION(&opts->proxy_opts, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options"); + GIT_ERROR_CHECK_VERSION(&opts->proxy_opts, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options"); proxy = &opts->proxy_opts; } @@ -1009,12 +1009,12 @@ int git_remote_fetch( git_remote_connection_opts conn = GIT_REMOTE_CONNECTION_OPTIONS_INIT; if (opts) { - GITERR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); + GIT_ERROR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); cbs = &opts->callbacks; conn.custom_headers = &opts->custom_headers; update_fetchhead = opts->update_fetchhead; tagopt = opts->download_tags; - GITERR_CHECK_VERSION(&opts->proxy_opts, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options"); + GIT_ERROR_CHECK_VERSION(&opts->proxy_opts, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options"); conn.proxy = &opts->proxy_opts; } @@ -1097,7 +1097,7 @@ static int ref_to_update(int *update, git_buf *remote_name, git_remote *remote, (error = git_refspec_rtransform(remote_name, spec, upstream_name.ptr)) < 0) { /* Not an error if there is no upstream */ if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = 0; } @@ -1232,7 +1232,7 @@ static int prune_candidates(git_vector *candidates, git_remote *remote) continue; refname_dup = git__strdup(refname); - GITERR_CHECK_ALLOC(refname_dup); + GIT_ERROR_CHECK_ALLOC(refname_dup); if ((error = git_vector_insert(candidates, refname_dup)) < 0) goto out; @@ -1262,7 +1262,7 @@ int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks) git_oid zero_id = {{ 0 }}; if (callbacks) - GITERR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); + GIT_ERROR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); if ((error = ls_to_vector(&remote_refs, remote)) < 0) goto cleanup; @@ -1737,7 +1737,7 @@ static int remote_list_cb(const git_config_entry *entry, void *payload) remote_name = git__strndup(name, namelen - 4); /* strip ".url" */ else remote_name = git__strndup(name, namelen - 8); /* strip ".pushurl" */ - GITERR_CHECK_ALLOC(remote_name); + GIT_ERROR_CHECK_ALLOC(remote_name); return git_vector_insert(list, remote_name); } @@ -1811,7 +1811,7 @@ int git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_ error = 0; break; default: - giterr_set(GITERR_INVALID, "invalid value for the tagopt setting"); + git_error_set(GIT_ERROR_INVALID, "invalid value for the tagopt setting"); error = -1; } @@ -2005,7 +2005,7 @@ static int rename_fetch_refspecs(git_vector *problems, git_remote *remote, const char *dup; dup = git__strdup(spec->string); - GITERR_CHECK_ALLOC(dup); + GIT_ERROR_CHECK_ALLOC(dup); if ((error = git_vector_insert(problems, dup)) < 0) break; @@ -2101,7 +2101,7 @@ int git_remote_is_valid_name( git_buf_dispose(&buf); git_refspec__dispose(&refspec); - giterr_clear(); + git_error_clear(); return error == 0; } @@ -2256,7 +2256,7 @@ static int remove_branch_config_related_entries( if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) { if (error != GIT_ENOTFOUND) break; - giterr_clear(); + git_error_clear(); } git_buf_clear(&buf); @@ -2266,7 +2266,7 @@ static int remove_branch_config_related_entries( if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) { if (error != GIT_ENOTFOUND) break; - giterr_clear(); + git_error_clear(); } } @@ -2432,7 +2432,7 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi assert(remote); if (!remote->repo) { - giterr_set(GITERR_INVALID, "cannot download detached remote"); + git_error_set(GIT_ERROR_INVALID, "cannot download detached remote"); return -1; } @@ -2498,15 +2498,15 @@ int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_ assert(remote); if (!remote->repo) { - giterr_set(GITERR_INVALID, "cannot download detached remote"); + git_error_set(GIT_ERROR_INVALID, "cannot download detached remote"); return -1; } if (opts) { - GITERR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); + GIT_ERROR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); cbs = &opts->callbacks; custom_headers = &opts->custom_headers; - GITERR_CHECK_VERSION(&opts->proxy_opts, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options"); + GIT_ERROR_CHECK_VERSION(&opts->proxy_opts, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options"); proxy = &opts->proxy_opts; } diff --git a/src/repository.c b/src/repository.c index 0f38f88f2..26936a82f 100644 --- a/src/repository.c +++ b/src/repository.c @@ -256,7 +256,7 @@ int git_repository_new(git_repository **out) git_repository *repo; *out = repo = repository_alloc(); - GITERR_CHECK_ALLOC(repo); + GIT_ERROR_CHECK_ALLOC(repo); repo->is_bare = 1; repo->is_worktree = 0; @@ -331,7 +331,7 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren repo->workdir = git_buf_detach(&worktree); } - GITERR_CHECK_ALLOC(repo->workdir); + GIT_ERROR_CHECK_ALLOC(repo->workdir); cleanup: git_buf_dispose(&path); git_config_entry_free(ce); @@ -413,7 +413,7 @@ static int read_gitfile(git_buf *path_out, const char *file_path) if (git_buf_len(&file) <= prefix_len || memcmp(git_buf_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0) { - giterr_set(GITERR_REPOSITORY, + git_error_set(GIT_ERROR_REPOSITORY, "the `.git` file at '%s' is malformed", file_path); error = -1; } @@ -551,7 +551,7 @@ static int find_repo( /* If we didn't find the repository, and we don't have any other error * to report, report that. */ if (!git_buf_len(gitdir_path) && !error) { - giterr_set(GITERR_REPOSITORY, + git_error_set(GIT_ERROR_REPOSITORY, "could not find repository from '%s'", start_path); error = GIT_ENOTFOUND; } @@ -576,17 +576,17 @@ int git_repository_open_bare( if (!valid_repository_path(&path, &common_path)) { git_buf_dispose(&path); git_buf_dispose(&common_path); - giterr_set(GITERR_REPOSITORY, "path is not a repository: %s", bare_path); + git_error_set(GIT_ERROR_REPOSITORY, "path is not a repository: %s", bare_path); return GIT_ENOTFOUND; } repo = repository_alloc(); - GITERR_CHECK_ALLOC(repo); + GIT_ERROR_CHECK_ALLOC(repo); repo->gitdir = git_buf_detach(&path); - GITERR_CHECK_ALLOC(repo->gitdir); + GIT_ERROR_CHECK_ALLOC(repo->gitdir); repo->commondir = git_buf_detach(&common_path); - GITERR_CHECK_ALLOC(repo->commondir); + GIT_ERROR_CHECK_ALLOC(repo->commondir); /* of course we're bare! */ repo->is_bare = 1; @@ -620,7 +620,7 @@ static int _git_repository_open_ext_from_env( if (!start_path) { error = git__getenv(&dir_buf, "GIT_DIR"); if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); start_path = "."; } else if (error < 0) goto error; @@ -633,7 +633,7 @@ static int _git_repository_open_ext_from_env( error = git__getenv(&ceiling_dirs_buf, "GIT_CEILING_DIRECTORIES"); if (error == GIT_ENOTFOUND) - giterr_clear(); + git_error_clear(); else if (error < 0) goto error; else @@ -641,7 +641,7 @@ static int _git_repository_open_ext_from_env( error = git__getenv(&across_fs_buf, "GIT_DISCOVERY_ACROSS_FILESYSTEM"); if (error == GIT_ENOTFOUND) - giterr_clear(); + git_error_clear(); else if (error < 0) goto error; else { @@ -655,7 +655,7 @@ static int _git_repository_open_ext_from_env( error = git__getenv(&index_file_buf, "GIT_INDEX_FILE"); if (error == GIT_ENOTFOUND) - giterr_clear(); + git_error_clear(); else if (error < 0) goto error; else { @@ -666,13 +666,13 @@ static int _git_repository_open_ext_from_env( error = git__getenv(&namespace_buf, "GIT_NAMESPACE"); if (error == GIT_ENOTFOUND) - giterr_clear(); + git_error_clear(); else if (error < 0) goto error; error = git__getenv(&object_dir_buf, "GIT_OBJECT_DIRECTORY"); if (error == GIT_ENOTFOUND) - giterr_clear(); + git_error_clear(); else if (error < 0) goto error; else { @@ -683,22 +683,22 @@ static int _git_repository_open_ext_from_env( error = git__getenv(&work_tree_buf, "GIT_WORK_TREE"); if (error == GIT_ENOTFOUND) - giterr_clear(); + git_error_clear(); else if (error < 0) goto error; else { - giterr_set(GITERR_INVALID, "GIT_WORK_TREE unimplemented"); + git_error_set(GIT_ERROR_INVALID, "GIT_WORK_TREE unimplemented"); error = GIT_ERROR; goto error; } error = git__getenv(&work_tree_buf, "GIT_COMMON_DIR"); if (error == GIT_ENOTFOUND) - giterr_clear(); + git_error_clear(); else if (error < 0) goto error; else { - giterr_set(GITERR_INVALID, "GIT_COMMON_DIR unimplemented"); + git_error_set(GIT_ERROR_INVALID, "GIT_COMMON_DIR unimplemented"); error = GIT_ERROR; goto error; } @@ -712,7 +712,7 @@ static int _git_repository_open_ext_from_env( error = git__getenv(&alts_buf, "GIT_ALTERNATE_OBJECT_DIRECTORIES"); if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = 0; } else if (error < 0) goto error; @@ -815,18 +815,18 @@ int git_repository_open_ext( return error; repo = repository_alloc(); - GITERR_CHECK_ALLOC(repo); + GIT_ERROR_CHECK_ALLOC(repo); repo->gitdir = git_buf_detach(&gitdir); - GITERR_CHECK_ALLOC(repo->gitdir); + GIT_ERROR_CHECK_ALLOC(repo->gitdir); if (gitlink.size) { repo->gitlink = git_buf_detach(&gitlink); - GITERR_CHECK_ALLOC(repo->gitlink); + GIT_ERROR_CHECK_ALLOC(repo->gitlink); } if (commondir.size) { repo->commondir = git_buf_detach(&commondir); - GITERR_CHECK_ALLOC(repo->commondir); + GIT_ERROR_CHECK_ALLOC(repo->commondir); } if ((error = repo_is_worktree(&is_worktree, repo)) < 0) @@ -909,7 +909,7 @@ int git_repository_wrap_odb(git_repository **repo_out, git_odb *odb) git_repository *repo; repo = repository_alloc(); - GITERR_CHECK_ALLOC(repo); + GIT_ERROR_CHECK_ALLOC(repo); git_repository_set_odb(repo, odb); *repo_out = repo; @@ -983,7 +983,7 @@ static int load_config( error != GIT_ENOTFOUND) goto on_error; - giterr_clear(); /* clear any lingering ENOTFOUND errors */ + git_error_clear(); /* clear any lingering ENOTFOUND errors */ *out = cfg; return 0; @@ -1344,7 +1344,7 @@ static int check_repositoryformatversion(git_config *config) return -1; if (GIT_REPO_VERSION < version) { - giterr_set(GITERR_REPOSITORY, + git_error_set(GIT_ERROR_REPOSITORY, "unsupported repository version %d. Only versions up to %d are supported.", version, GIT_REPO_VERSION); return -1; @@ -1474,12 +1474,12 @@ static int create_empty_file(const char *path, mode_t mode) int fd; if ((fd = p_creat(path, mode)) < 0) { - giterr_set(GITERR_OS, "error while creating '%s'", path); + git_error_set(GIT_ERROR_OS, "error while creating '%s'", path); return -1; } if (p_close(fd) < 0) { - giterr_set(GITERR_OS, "error while closing '%s'", path); + git_error_set(GIT_ERROR_OS, "error while closing '%s'", path); return -1; } @@ -1514,7 +1514,7 @@ static int repo_local_config( return error; if (git_config_open_level(out, parent, GIT_CONFIG_LEVEL_LOCAL) < 0) { - giterr_clear(); + git_error_clear(); if (!(error = git_config_add_file_ondisk( parent, cfg_path, GIT_CONFIG_LEVEL_LOCAL, repo, false))) @@ -1546,14 +1546,14 @@ static int repo_init_fs_configs( if ((error = git_config_set_bool(cfg, "core.symlinks", false)) < 0) return error; } else if (git_config_delete_entry(cfg, "core.symlinks") < 0) - giterr_clear(); + git_error_clear(); if (update_ignorecase) { if (is_filesystem_case_insensitive(repo_dir)) { if ((error = git_config_set_bool(cfg, "core.ignorecase", true)) < 0) return error; } else if (git_config_delete_entry(cfg, "core.ignorecase") < 0) - giterr_clear(); + git_error_clear(); } #ifdef GIT_USE_ICONV @@ -1610,7 +1610,7 @@ static int repo_init_config( SET_REPO_CONFIG(string, "core.worktree", worktree_path.ptr); } else if (is_reinit) { if (git_config_delete_entry(config, "core.worktree") < 0) - giterr_clear(); + git_error_clear(); } } @@ -1638,7 +1638,7 @@ static int repo_reinit_submodule_fs(git_submodule *sm, const char *n, void *p) if (git_submodule_open(&smrepo, sm) < 0 || git_repository_reinit_filesystem(smrepo, true) < 0) - giterr_clear(); + git_error_clear(); git_repository_free(smrepo); return 0; @@ -1707,7 +1707,7 @@ static int repo_write_template( git_buf_dispose(&path); if (error) - giterr_set(GITERR_OS, + git_error_set(GIT_ERROR_OS, "failed to initialize repository with template '%s'", file); return error; @@ -1738,7 +1738,7 @@ static int repo_write_gitlink( goto cleanup; if (!p_stat(buf.ptr, &st) && !S_ISREG(st.st_mode)) { - giterr_set(GITERR_REPOSITORY, + git_error_set(GIT_ERROR_REPOSITORY, "cannot overwrite gitlink file into path '%s'", in_dir); error = GIT_EEXISTS; goto cleanup; @@ -1792,7 +1792,7 @@ static int repo_init_structure( #ifdef GIT_WIN32 if ((opts->flags & GIT_REPOSITORY_INIT__HAS_DOTGIT) != 0) { if (git_win32__set_hidden(repo_dir, true) < 0) { - giterr_set(GITERR_OS, + git_error_set(GIT_ERROR_OS, "failed to mark Git repository folder as hidden"); return -1; } @@ -1819,7 +1819,7 @@ static int repo_init_structure( else if ((error = git_config_open_default(&cfg)) >= 0) { if (!git_config_get_path(&template_buf, cfg, "init.templatedir")) tdir = template_buf.ptr; - giterr_clear(); + git_error_clear(); } if (!tdir) { @@ -1851,7 +1851,7 @@ static int repo_init_structure( return error; /* if template was default, ignore error and use internal */ - giterr_clear(); + git_error_clear(); external_tpl = false; error = 0; } @@ -1953,7 +1953,7 @@ static int repo_init_directories( if (git_path_dirname_r(wd_path, repo_path->ptr) < 0) return -1; } else { - giterr_set(GITERR_REPOSITORY, "cannot pick working directory" + git_error_set(GIT_ERROR_REPOSITORY, "cannot pick working directory" " for non-bare repository that isn't a '.git' directory"); return -1; } @@ -2063,7 +2063,7 @@ int git_repository_init_ext( assert(out && given_repo && opts); - GITERR_CHECK_VERSION(opts, GIT_REPOSITORY_INIT_OPTIONS_VERSION, "git_repository_init_options"); + GIT_ERROR_CHECK_VERSION(opts, GIT_REPOSITORY_INIT_OPTIONS_VERSION, "git_repository_init_options"); error = repo_init_directories(&repo_path, &wd_path, given_repo, opts); if (error < 0) @@ -2073,7 +2073,7 @@ int git_repository_init_ext( if (valid_repository_path(&repo_path, &common_path)) { if ((opts->flags & GIT_REPOSITORY_INIT_NO_REINIT) != 0) { - giterr_set(GITERR_REPOSITORY, + git_error_set(GIT_ERROR_REPOSITORY, "attempt to reinitialize '%s'", given_repo); error = GIT_EEXISTS; goto cleanup; @@ -2251,7 +2251,7 @@ int git_repository_head_unborn(git_repository *repo) git_reference_free(ref); if (error == GIT_EUNBORNBRANCH) { - giterr_clear(); + git_error_clear(); return 1; } @@ -2315,12 +2315,12 @@ int git_repository_item_path(git_buf *out, const git_repository *repo, git_repos parent = git_repository_commondir(repo); break; default: - giterr_set(GITERR_INVALID, "invalid item directory"); + git_error_set(GIT_ERROR_INVALID, "invalid item directory"); return -1; } if (parent == NULL) { - giterr_set(GITERR_INVALID, "path cannot exist in repository"); + git_error_set(GIT_ERROR_INVALID, "path cannot exist in repository"); return GIT_ENOTFOUND; } @@ -2499,7 +2499,7 @@ int git_repository_message(git_buf *out, git_repository *repo) if ((error = p_stat(git_buf_cstr(&path), &st)) < 0) { if (errno == ENOENT) error = GIT_ENOTFOUND; - giterr_set(GITERR_OS, "could not access message file"); + git_error_set(GIT_ERROR_OS, "could not access message file"); } else { error = git_futils_readbuffer(out, git_buf_cstr(&path)); } @@ -2577,7 +2577,7 @@ int git_repository_hashfile( } if (!git__is_sizet(len)) { - giterr_set(GITERR_OS, "file size overflow for 32-bit systems"); + git_error_set(GIT_ERROR_OS, "file size overflow for 32-bit systems"); error = -1; goto cleanup; } @@ -2674,7 +2674,7 @@ int git_repository_set_head( if (ref && current->type == GIT_REFERENCE_SYMBOLIC && git__strcmp(current->target.symbolic, ref->name) && git_reference_is_branch(ref) && git_branch_is_checked_out(ref)) { - giterr_set(GITERR_REPOSITORY, "cannot set HEAD to reference '%s' as it is the current HEAD " + git_error_set(GIT_ERROR_REPOSITORY, "cannot set HEAD to reference '%s' as it is the current HEAD " "of a linked repository.", git_reference_name(ref)); error = -1; goto cleanup; @@ -2854,7 +2854,7 @@ int git_repository_is_shallow(git_repository *repo) git_buf_dispose(&path); if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); return 0; } @@ -2886,12 +2886,12 @@ int git_repository_set_ident(git_repository *repo, const char *name, const char if (name) { tmp_name = git__strdup(name); - GITERR_CHECK_ALLOC(tmp_name); + GIT_ERROR_CHECK_ALLOC(tmp_name); } if (email) { tmp_email = git__strdup(email); - GITERR_CHECK_ALLOC(tmp_email); + GIT_ERROR_CHECK_ALLOC(tmp_email); } tmp_name = git__swap(repo->ident_name, tmp_name); diff --git a/src/repository.h b/src/repository.h index 1a7271799..1edcc842b 100644 --- a/src/repository.h +++ b/src/repository.h @@ -214,8 +214,8 @@ GIT_INLINE(int) git_repository__ensure_not_bare( if (!git_repository_is_bare(repo)) return 0; - giterr_set( - GITERR_REPOSITORY, + git_error_set( + GIT_ERROR_REPOSITORY, "cannot %s. This operation is not allowed against bare repositories.", operation_name); diff --git a/src/reset.c b/src/reset.c index b8d69e748..ca6a5bd73 100644 --- a/src/reset.c +++ b/src/reset.c @@ -42,7 +42,7 @@ int git_reset_default( if (target) { if (git_object_owner(target) != repo) { - giterr_set(GITERR_OBJECT, + git_error_set(GIT_ERROR_OBJECT, "%s_default - The given target does not belong to this repository.", ERROR_MSG); return -1; } @@ -70,7 +70,7 @@ int git_reset_default( error = git_index_conflict_remove(index, delta->old_file.path); if (error < 0) { if (delta->status == GIT_DELTA_ADDED && error == GIT_ENOTFOUND) - giterr_clear(); + git_error_clear(); else goto cleanup; } @@ -119,7 +119,7 @@ static int reset( opts = *checkout_opts; if (git_object_owner(target) != repo) { - giterr_set(GITERR_OBJECT, + git_error_set(GIT_ERROR_OBJECT, "%s - The given target does not belong to this repository.", ERROR_MSG); return -1; } @@ -138,7 +138,7 @@ static int reset( (git_repository_state(repo) == GIT_REPOSITORY_STATE_MERGE || git_index_has_conflicts(index))) { - giterr_set(GITERR_OBJECT, "%s (soft) in the middle of a merge", ERROR_MSG); + git_error_set(GIT_ERROR_OBJECT, "%s (soft) in the middle of a merge", ERROR_MSG); error = GIT_EUNMERGED; goto cleanup; } @@ -167,7 +167,7 @@ static int reset( goto cleanup; if ((error = git_repository_state_cleanup(repo)) < 0) { - giterr_set(GITERR_INDEX, "%s - failed to clean up merge data", ERROR_MSG); + git_error_set(GIT_ERROR_INDEX, "%s - failed to clean up merge data", ERROR_MSG); goto cleanup; } } diff --git a/src/revert.c b/src/revert.c index 32c8a3910..eb71a68db 100644 --- a/src/revert.c +++ b/src/revert.c @@ -112,7 +112,7 @@ static int revert_seterr(git_commit *commit, const char *fmt) git_oid_fmt(commit_oidstr, git_commit_id(commit)); commit_oidstr[GIT_OID_HEXSZ] = '\0'; - giterr_set(GITERR_REVERT, fmt, commit_oidstr); + git_error_set(GIT_ERROR_REVERT, fmt, commit_oidstr); return -1; } @@ -182,7 +182,7 @@ int git_revert( assert(repo && commit); - GITERR_CHECK_VERSION(given_opts, GIT_REVERT_OPTIONS_VERSION, "git_revert_options"); + GIT_ERROR_CHECK_VERSION(given_opts, GIT_REVERT_OPTIONS_VERSION, "git_revert_options"); if ((error = git_repository__ensure_not_bare(repo, "revert")) < 0) return error; diff --git a/src/revparse.c b/src/revparse.c index 78d879bba..50ee31ca0 100644 --- a/src/revparse.c +++ b/src/revparse.c @@ -47,7 +47,7 @@ static int build_regex(regex_t *regex, const char *pattern) int error; if (*pattern == '\0') { - giterr_set(GITERR_REGEX, "empty pattern"); + git_error_set(GIT_ERROR_REGEX, "empty pattern"); return GIT_EINVALIDSPEC; } @@ -55,7 +55,7 @@ static int build_regex(regex_t *regex, const char *pattern) if (!error) return 0; - error = giterr_set_regex(regex, error); + error = git_error_set_regex(regex, error); regfree(regex); @@ -119,7 +119,7 @@ static int revparse_lookup_object( if ((error = maybe_describe(object_out, repo, spec)) != GIT_ENOTFOUND) return error; - giterr_set(GITERR_REFERENCE, "revspec '%s' not found", spec); + git_error_set(GIT_ERROR_REFERENCE, "revspec '%s' not found", spec); return GIT_ENOTFOUND; } @@ -245,8 +245,8 @@ static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, size_t ide return 0; notfound: - giterr_set( - GITERR_REFERENCE, + git_error_set( + GIT_ERROR_REFERENCE, "reflog for '%s' has only %"PRIuZ" entries, asked for %"PRIuZ, git_reference_name(ref), numentries, identifier); @@ -759,7 +759,7 @@ int revparse__ext( * TODO: support merge-stage path lookup (":2:Makefile") * and plain index blob lookup (:i-am/a/blob) */ - giterr_set(GITERR_INVALID, "unimplemented"); + git_error_set(GIT_ERROR_INVALID, "unimplemented"); error = GIT_ERROR; goto cleanup; } @@ -814,7 +814,7 @@ int revparse__ext( cleanup: if (error) { if (error == GIT_EINVALIDSPEC) - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "failed to parse revision specifier - Invalid pattern '%s'", spec); git_object_free(base_rev); @@ -898,7 +898,7 @@ int git_revparse( * allowed. */ if (!git__strcmp(spec, "..")) { - giterr_set(GITERR_INVALID, "Invalid pattern '..'"); + git_error_set(GIT_ERROR_INVALID, "Invalid pattern '..'"); return GIT_EINVALIDSPEC; } diff --git a/src/revwalk.c b/src/revwalk.c index f3442ae9d..1e3a5f2ff 100644 --- a/src/revwalk.c +++ b/src/revwalk.c @@ -61,7 +61,7 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting, if (from_glob) return 0; - giterr_set(GITERR_INVALID, "object is not a committish"); + git_error_set(GIT_ERROR_INVALID, "object is not a committish"); return -1; } if (error < 0) @@ -88,7 +88,7 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting, commit->uninteresting = uninteresting; list = walk->user_input; if (git_commit_list_insert(commit, &list) == NULL) { - giterr_set_oom(); + git_error_set_oom(); return -1; } @@ -135,7 +135,7 @@ static int push_glob(git_revwalk *walk, const char *glob, int hide) git_buf_joinpath(&buf, GIT_REFS_DIR, glob); else git_buf_puts(&buf, glob); - GITERR_CHECK_ALLOC_BUF(&buf); + GIT_ERROR_CHECK_ALLOC_BUF(&buf); /* If no '?', '*' or '[' exist, we append '/ *' to the glob */ wildcard = strcspn(glob, "?*["); @@ -200,7 +200,7 @@ int git_revwalk_push_range(git_revwalk *walk, const char *range) if (revspec.flags & GIT_REVPARSE_MERGE_BASE) { /* TODO: support "<commit>...<commit>" */ - giterr_set(GITERR_INVALID, "symmetric differences not implemented in revwalk"); + git_error_set(GIT_ERROR_INVALID, "symmetric differences not implemented in revwalk"); return GIT_EINVALIDSPEC; } @@ -243,7 +243,7 @@ static int revwalk_next_timesort(git_commit_list_node **object_out, git_revwalk } } - giterr_clear(); + git_error_clear(); return GIT_ITEROVER; } @@ -451,7 +451,7 @@ static int get_revision(git_commit_list_node **out, git_revwalk *walk, git_commi commit = git_commit_list_pop(list); if (!commit) { - giterr_clear(); + git_error_clear(); return GIT_ITEROVER; } @@ -562,7 +562,7 @@ static int prepare_walk(git_revwalk *walk) /* If there were no pushes, we know that the walk is already over */ if (!walk->did_push) { - giterr_clear(); + git_error_clear(); return GIT_ITEROVER; } @@ -624,10 +624,10 @@ static int prepare_walk(git_revwalk *walk) int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo) { git_revwalk *walk = git__calloc(1, sizeof(git_revwalk)); - GITERR_CHECK_ALLOC(walk); + GIT_ERROR_CHECK_ALLOC(walk); walk->commits = git_oidmap_alloc(); - GITERR_CHECK_ALLOC(walk->commits); + GIT_ERROR_CHECK_ALLOC(walk->commits); if (git_pqueue_init(&walk->iterator_time, 0, 8, git_commit_list_time_cmp) < 0) return -1; @@ -709,7 +709,7 @@ int git_revwalk_next(git_oid *oid, git_revwalk *walk) if (error == GIT_ITEROVER) { git_revwalk_reset(walk); - giterr_clear(); + git_error_clear(); return GIT_ITEROVER; } diff --git a/src/settings.c b/src/settings.c index d71841acf..95cbd89e4 100644 --- a/src/settings.c +++ b/src/settings.c @@ -76,8 +76,8 @@ static int config_level_to_sysdir(int config_level) val = GIT_SYSDIR_PROGRAMDATA; break; default: - giterr_set( - GITERR_INVALID, "invalid config path selector %d", config_level); + git_error_set( + GIT_ERROR_INVALID, "invalid config path selector %d", config_level); } return val; @@ -193,7 +193,7 @@ int git_libgit2_opts(int key, ...) error = git_mbedtls__set_cert_location(path, 1); } #else - giterr_set(GITERR_SSL, "TLS backend doesn't support certificate locations"); + git_error_set(GIT_ERROR_SSL, "TLS backend doesn't support certificate locations"); error = -1; #endif break; @@ -201,7 +201,7 @@ int git_libgit2_opts(int key, ...) git__free(git__user_agent); git__user_agent = git__strdup(va_arg(ap, const char *)); if (!git__user_agent) { - giterr_set_oom(); + git_error_set_oom(); error = -1; } @@ -221,12 +221,12 @@ int git_libgit2_opts(int key, ...) git__free(git__ssl_ciphers); git__ssl_ciphers = git__strdup(va_arg(ap, const char *)); if (!git__ssl_ciphers) { - giterr_set_oom(); + git_error_set_oom(); error = -1; } } #else - giterr_set(GITERR_SSL, "TLS backend doesn't support custom ciphers"); + git_error_set(GIT_ERROR_SSL, "TLS backend doesn't support custom ciphers"); error = -1; #endif break; @@ -280,7 +280,7 @@ int git_libgit2_opts(int key, ...) break; default: - giterr_set(GITERR_INVALID, "invalid option key"); + git_error_set(GIT_ERROR_INVALID, "invalid option key"); error = -1; } diff --git a/src/signature.c b/src/signature.c index 11416d786..f4c8a104a 100644 --- a/src/signature.c +++ b/src/signature.c @@ -25,7 +25,7 @@ void git_signature_free(git_signature *sig) static int signature_error(const char *msg) { - giterr_set(GITERR_INVALID, "failed to parse signature - %s", msg); + git_error_set(GIT_ERROR_INVALID, "failed to parse signature - %s", msg); return -1; } @@ -76,12 +76,12 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema } p = git__calloc(1, sizeof(git_signature)); - GITERR_CHECK_ALLOC(p); + GIT_ERROR_CHECK_ALLOC(p); p->name = extract_trimmed(name, strlen(name)); - GITERR_CHECK_ALLOC(p->name); + GIT_ERROR_CHECK_ALLOC(p->name); p->email = extract_trimmed(email, strlen(email)); - GITERR_CHECK_ALLOC(p->email); + GIT_ERROR_CHECK_ALLOC(p->email); if (p->name[0] == '\0' || p->email[0] == '\0') { git_signature_free(p); @@ -104,13 +104,13 @@ int git_signature_dup(git_signature **dest, const git_signature *source) return 0; signature = git__calloc(1, sizeof(git_signature)); - GITERR_CHECK_ALLOC(signature); + GIT_ERROR_CHECK_ALLOC(signature); signature->name = git__strdup(source->name); - GITERR_CHECK_ALLOC(signature->name); + GIT_ERROR_CHECK_ALLOC(signature->name); signature->email = git__strdup(source->email); - GITERR_CHECK_ALLOC(signature->email); + GIT_ERROR_CHECK_ALLOC(signature->email); signature->when.time = source->when.time; signature->when.offset = source->when.offset; @@ -129,13 +129,13 @@ int git_signature__pdup(git_signature **dest, const git_signature *source, git_p return 0; signature = git_pool_mallocz(pool, sizeof(git_signature)); - GITERR_CHECK_ALLOC(signature); + GIT_ERROR_CHECK_ALLOC(signature); signature->name = git_pool_strdup(pool, source->name); - GITERR_CHECK_ALLOC(signature->name); + GIT_ERROR_CHECK_ALLOC(signature->name); signature->email = git_pool_strdup(pool, source->email); - GITERR_CHECK_ALLOC(signature->email); + GIT_ERROR_CHECK_ALLOC(signature->email); signature->when.time = source->when.time; signature->when.offset = source->when.offset; @@ -284,7 +284,7 @@ int git_signature_from_buffer(git_signature **out, const char *buf) *out = NULL; sig = git__calloc(1, sizeof(git_signature)); - GITERR_CHECK_ALLOC(sig); + GIT_ERROR_CHECK_ALLOC(sig); buf_end = buf + strlen(buf); error = git_signature__parse(sig, &buf, buf_end, NULL, '\0'); diff --git a/src/sortedcache.c b/src/sortedcache.c index bb42c67c2..02a685e10 100644 --- a/src/sortedcache.c +++ b/src/sortedcache.c @@ -20,10 +20,10 @@ int git_sortedcache_new( pathlen = path ? strlen(path) : 0; - GITERR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_sortedcache), pathlen); - GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_sortedcache), pathlen); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); sc = git__calloc(1, alloclen); - GITERR_CHECK_ALLOC(sc); + GIT_ERROR_CHECK_ALLOC(sc); git_pool_init(&sc->pool, 1); @@ -32,7 +32,7 @@ int git_sortedcache_new( goto fail; if (git_rwlock_init(&sc->lock)) { - giterr_set(GITERR_OS, "failed to initialize lock"); + git_error_set(GIT_ERROR_OS, "failed to initialize lock"); goto fail; } @@ -167,7 +167,7 @@ int git_sortedcache_wlock(git_sortedcache *sc) GIT_UNUSED(sc); /* prevent warning when compiled w/o threads */ if (git_rwlock_wrlock(&sc->lock) < 0) { - giterr_set(GITERR_OS, "unable to acquire write lock on cache"); + git_error_set(GIT_ERROR_OS, "unable to acquire write lock on cache"); return -1; } return 0; @@ -186,7 +186,7 @@ int git_sortedcache_rlock(git_sortedcache *sc) GIT_UNUSED(sc); /* prevent warning when compiled w/o threads */ if (git_rwlock_rdlock(&sc->lock) < 0) { - giterr_set(GITERR_OS, "unable to acquire read lock on cache"); + git_error_set(GIT_ERROR_OS, "unable to acquire read lock on cache"); return -1; } return 0; @@ -219,14 +219,14 @@ int git_sortedcache_lockandload(git_sortedcache *sc, git_buf *buf) } if (p_fstat(fd, &st) < 0) { - giterr_set(GITERR_OS, "failed to stat file"); + git_error_set(GIT_ERROR_OS, "failed to stat file"); error = -1; (void)p_close(fd); goto unlock; } if (!git__is_sizet(st.st_size)) { - giterr_set(GITERR_INVALID, "unable to load file larger than size_t"); + git_error_set(GIT_ERROR_INVALID, "unable to load file larger than size_t"); error = -1; (void)p_close(fd); goto unlock; @@ -287,7 +287,7 @@ int git_sortedcache_upsert(void **out, git_sortedcache *sc, const char *key) itemlen = (itemlen + 7) & ~7; if ((item = git_pool_mallocz(&sc->pool, (uint32_t)itemlen)) == NULL) { - /* don't use GITERR_CHECK_ALLOC b/c of lock */ + /* don't use GIT_ERROR_CHECK_ALLOC b/c of lock */ error = -1; goto done; } @@ -378,7 +378,7 @@ int git_sortedcache_remove(git_sortedcache *sc, size_t pos) */ if ((item = git_vector_get(&sc->items, pos)) == NULL) { - giterr_set(GITERR_INVALID, "removing item out of range"); + git_error_set(GIT_ERROR_INVALID, "removing item out of range"); return GIT_ENOTFOUND; } diff --git a/src/stash.c b/src/stash.c index cb542a36c..c332d93bb 100644 --- a/src/stash.c +++ b/src/stash.c @@ -29,7 +29,7 @@ static int create_error(int error, const char *msg) { - giterr_set(GITERR_STASH, "cannot stash changes - %s", msg); + git_error_set(GIT_ERROR_STASH, "cannot stash changes - %s", msg); return error; } @@ -48,7 +48,7 @@ static int append_abbreviated_oid(git_buf *out, const git_oid *b_commit) char *formatted_oid; formatted_oid = git_oid_allocfmt(b_commit); - GITERR_CHECK_ALLOC(formatted_oid); + GIT_ERROR_CHECK_ALLOC(formatted_oid); git_buf_put(out, formatted_oid, 7); git__free(formatted_oid); @@ -59,7 +59,7 @@ static int append_abbreviated_oid(git_buf *out, const git_oid *b_commit) static int append_commit_description(git_buf *out, git_commit* commit) { const char *summary = git_commit_summary(commit); - GITERR_CHECK_ALLOC(summary); + GIT_ERROR_CHECK_ALLOC(summary); if (append_abbreviated_oid(out, git_commit_id(commit)) < 0) return -1; @@ -233,8 +233,8 @@ static int stash_update_index_from_diff( default: /* Unimplemented */ - giterr_set( - GITERR_INVALID, + git_error_set( + GIT_ERROR_INVALID, "cannot update index. Unimplemented status (%d)", delta->status); return -1; @@ -641,7 +641,7 @@ static int retrieve_stash_commit( max = git_reflog_entrycount(reflog); if (!max || index > max - 1) { error = GIT_ENOTFOUND; - giterr_set(GITERR_STASH, "no stashed state at position %" PRIuZ, index); + git_error_set(GIT_ERROR_STASH, "no stashed state at position %" PRIuZ, index); goto cleanup; } @@ -822,7 +822,7 @@ static int ensure_clean_index(git_repository *repo, git_index *index) goto done; if (git_diff_num_deltas(index_diff) > 0) { - giterr_set(GITERR_STASH, "%" PRIuZ " uncommitted changes exist in the index", + git_error_set(GIT_ERROR_STASH, "%" PRIuZ " uncommitted changes exist in the index", git_diff_num_deltas(index_diff)); error = GIT_EUNCOMMITTED; } @@ -894,7 +894,7 @@ int git_stash_apply( git_index *untracked_index = NULL; int error; - GITERR_CHECK_VERSION(given_opts, GIT_STASH_APPLY_OPTIONS_VERSION, "git_stash_apply_options"); + GIT_ERROR_CHECK_VERSION(given_opts, GIT_STASH_APPLY_OPTIONS_VERSION, "git_stash_apply_options"); normalize_apply_options(&opts, given_opts); checkout_strategy = opts.checkout_options.checkout_strategy; @@ -1027,7 +1027,7 @@ int git_stash_foreach( error = git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE); if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); return 0; } if (error < 0) @@ -1046,7 +1046,7 @@ int git_stash_foreach( payload); if (error) { - giterr_set_after_callback(error); + git_error_set_after_callback(error); break; } } @@ -1083,7 +1083,7 @@ int git_stash_drop( if (!max || index > max - 1) { error = GIT_ENOTFOUND; - giterr_set(GITERR_STASH, "no stashed state at position %" PRIuZ, index); + git_error_set(GIT_ERROR_STASH, "no stashed state at position %" PRIuZ, index); goto cleanup; } diff --git a/src/status.c b/src/status.c index a2d389860..ef32a0a8e 100644 --- a/src/status.c +++ b/src/status.c @@ -174,7 +174,7 @@ static int status_collect( return 0; status_entry = git__malloc(sizeof(git_status_entry)); - GITERR_CHECK_ALLOC(status_entry); + GIT_ERROR_CHECK_ALLOC(status_entry); status_entry->status = status_compute(status, head2idx, idx2wd); status_entry->head_to_index = head2idx; @@ -240,16 +240,16 @@ static int status_validate_options(const git_status_options *opts) if (!opts) return 0; - GITERR_CHECK_VERSION(opts, GIT_STATUS_OPTIONS_VERSION, "git_status_options"); + GIT_ERROR_CHECK_VERSION(opts, GIT_STATUS_OPTIONS_VERSION, "git_status_options"); if (opts->show > GIT_STATUS_SHOW_WORKDIR_ONLY) { - giterr_set(GITERR_INVALID, "unknown status 'show' option"); + git_error_set(GIT_ERROR_INVALID, "unknown status 'show' option"); return -1; } if ((opts->flags & GIT_STATUS_OPT_NO_REFRESH) != 0 && (opts->flags & GIT_STATUS_OPT_UPDATE_INDEX) != 0) { - giterr_set(GITERR_INVALID, "updating index from status " + git_error_set(GIT_ERROR_INVALID, "updating index from status " "is not allowed when index refresh is disabled"); return -1; } @@ -288,17 +288,17 @@ int git_status_list_new( if ((error = git_repository_head_tree(&head, repo)) < 0) { if (error != GIT_ENOTFOUND && error != GIT_EUNBORNBRANCH) goto done; - giterr_clear(); + git_error_clear(); } } /* refresh index from disk unless prevented */ if ((flags & GIT_STATUS_OPT_NO_REFRESH) == 0 && git_index_read_safely(index) < 0) - giterr_clear(); + git_error_clear(); status = git_status_list_alloc(index); - GITERR_CHECK_ALLOC(status); + GIT_ERROR_CHECK_ALLOC(status); if (opts) { memcpy(&status->opts, opts, sizeof(git_status_options)); @@ -437,7 +437,7 @@ int git_status_foreach_ext( status_entry->index_to_workdir->old_file.path; if ((error = cb(path, status_entry->status, payload)) != 0) { - giterr_set_after_callback(error); + git_error_set_after_callback(error); break; } } @@ -475,7 +475,7 @@ static int get_one_status(const char *path, unsigned int status, void *data) p_fnmatch(sfi->expected, path, sfi->fnm_flags) != 0)) { sfi->ambiguous = true; - return GIT_EAMBIGUOUS; /* giterr_set will be done by caller */ + return GIT_EAMBIGUOUS; /* git_error_set will be done by caller */ } return 0; @@ -514,13 +514,13 @@ int git_status_file( error = git_status_foreach_ext(repo, &opts, get_one_status, &sfi); if (error < 0 && sfi.ambiguous) { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "ambiguous path '%s' given to git_status_file", sfi.expected); error = GIT_EAMBIGUOUS; } if (!error && !sfi.count) { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "attempt to get status of nonexistent file '%s'", path); error = GIT_ENOTFOUND; } @@ -551,7 +551,7 @@ int git_status_list_get_perfdata( git_diff_perfdata *out, const git_status_list *status) { 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 = 0; out->oid_calculations = 0; diff --git a/src/stdalloc.c b/src/stdalloc.c index 171c9ed65..c6d4ec80c 100644 --- a/src/stdalloc.c +++ b/src/stdalloc.c @@ -14,7 +14,7 @@ static void *stdalloc__malloc(size_t len, const char *file, int line) GIT_UNUSED(file); GIT_UNUSED(line); - if (!ptr) giterr_set_oom(); + if (!ptr) git_error_set_oom(); return ptr; } @@ -25,7 +25,7 @@ static void *stdalloc__calloc(size_t nelem, size_t elsize, const char *file, int GIT_UNUSED(file); GIT_UNUSED(line); - if (!ptr) giterr_set_oom(); + if (!ptr) git_error_set_oom(); return ptr; } @@ -36,7 +36,7 @@ static char *stdalloc__strdup(const char *str, const char *file, int line) GIT_UNUSED(file); GIT_UNUSED(line); - if (!ptr) giterr_set_oom(); + if (!ptr) git_error_set_oom(); return ptr; } @@ -80,7 +80,7 @@ static void *stdalloc__realloc(void *ptr, size_t size, const char *file, int lin GIT_UNUSED(file); GIT_UNUSED(line); - if (!new_ptr) giterr_set_oom(); + if (!new_ptr) git_error_set_oom(); return new_ptr; } diff --git a/src/stream.h b/src/stream.h index d35477591..00220d50e 100644 --- a/src/stream.h +++ b/src/stream.h @@ -23,7 +23,7 @@ GIT_INLINE(int) git_stream_is_encrypted(git_stream *st) GIT_INLINE(int) git_stream_certificate(git_cert **out, git_stream *st) { if (!st->encrypted) { - giterr_set(GITERR_INVALID, "an unencrypted stream does not have a certificate"); + git_error_set(GIT_ERROR_INVALID, "an unencrypted stream does not have a certificate"); return -1; } @@ -38,7 +38,7 @@ GIT_INLINE(int) git_stream_supports_proxy(git_stream *st) GIT_INLINE(int) git_stream_set_proxy(git_stream *st, const git_proxy_options *proxy_opts) { if (!st->proxy_support) { - giterr_set(GITERR_INVALID, "proxy not supported on this stream"); + git_error_set(GIT_ERROR_INVALID, "proxy not supported on this stream"); return -1; } diff --git a/src/streams/mbedtls.c b/src/streams/mbedtls.c index d22f77069..45f5b6e75 100644 --- a/src/streams/mbedtls.c +++ b/src/streams/mbedtls.c @@ -83,14 +83,14 @@ int git_mbedtls_stream_global_init(void) char *cipher_string_tmp = NULL; git__ssl_conf = git__malloc(sizeof(mbedtls_ssl_config)); - GITERR_CHECK_ALLOC(git__ssl_conf); + GIT_ERROR_CHECK_ALLOC(git__ssl_conf); mbedtls_ssl_config_init(git__ssl_conf); if (mbedtls_ssl_config_defaults(git__ssl_conf, MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT) != 0) { - giterr_set(GITERR_SSL, "failed to initialize mbedTLS"); + git_error_set(GIT_ERROR_SSL, "failed to initialize mbedTLS"); goto cleanup; } @@ -105,14 +105,14 @@ int git_mbedtls_stream_global_init(void) /* set the list of allowed ciphersuites */ ciphers_known = 0; cipher_string = cipher_string_tmp = git__strdup(GIT_SSL_DEFAULT_CIPHERS); - GITERR_CHECK_ALLOC(cipher_string); + GIT_ERROR_CHECK_ALLOC(cipher_string); while ((cipher_name = git__strtok(&cipher_string_tmp, ":")) != NULL) { int cipherid = mbedtls_ssl_get_ciphersuite_id(cipher_name); if (cipherid == 0) continue; if (ciphers_known >= ARRAY_SIZE(ciphers_list)) { - giterr_set(GITERR_SSL, "out of cipher list space"); + git_error_set(GIT_ERROR_SSL, "out of cipher list space"); goto cleanup; } @@ -121,26 +121,26 @@ int git_mbedtls_stream_global_init(void) git__free(cipher_string); if (!ciphers_known) { - giterr_set(GITERR_SSL, "no cipher could be enabled"); + git_error_set(GIT_ERROR_SSL, "no cipher could be enabled"); goto cleanup; } mbedtls_ssl_conf_ciphersuites(git__ssl_conf, ciphers_list); /* Seeding the random number generator */ mbedtls_entropy = git__malloc(sizeof(mbedtls_entropy_context)); - GITERR_CHECK_ALLOC(mbedtls_entropy); + GIT_ERROR_CHECK_ALLOC(mbedtls_entropy); mbedtls_entropy_init(mbedtls_entropy); ctr_drbg = git__malloc(sizeof(mbedtls_ctr_drbg_context)); - GITERR_CHECK_ALLOC(ctr_drbg); + GIT_ERROR_CHECK_ALLOC(ctr_drbg); mbedtls_ctr_drbg_init(ctr_drbg); if (mbedtls_ctr_drbg_seed(ctr_drbg, mbedtls_entropy_func, mbedtls_entropy, NULL, 0) != 0) { - giterr_set(GITERR_SSL, "failed to initialize mbedTLS entropy pool"); + git_error_set(GIT_ERROR_SSL, "failed to initialize mbedTLS entropy pool"); goto cleanup; } @@ -193,16 +193,16 @@ static int ssl_set_error(mbedtls_ssl_context *ssl, int error) switch(error) { case 0: - giterr_set(GITERR_SSL, "SSL error: unknown error"); + git_error_set(GIT_ERROR_SSL, "SSL error: unknown error"); break; case MBEDTLS_ERR_X509_CERT_VERIFY_FAILED: - giterr_set(GITERR_SSL, "SSL error: %#04x [%x] - %s", error, ssl->session_negotiate->verify_result, errbuf); + git_error_set(GIT_ERROR_SSL, "SSL error: %#04x [%x] - %s", error, ssl->session_negotiate->verify_result, errbuf); ret = GIT_ECERTIFICATE; break; default: - giterr_set(GITERR_SSL, "SSL error: %#04x - %s", error, errbuf); + git_error_set(GIT_ERROR_SSL, "SSL error: %#04x - %s", error, errbuf); } return ret; @@ -228,7 +228,7 @@ static int verify_server_cert(mbedtls_ssl_context *ssl) char vrfy_buf[512]; int len = mbedtls_x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), "", ret); if (len >= 1) vrfy_buf[len - 1] = '\0'; /* Remove trailing \n */ - giterr_set(GITERR_SSL, "the SSL certificate is invalid: %#04x - %s", ret, vrfy_buf); + git_error_set(GIT_ERROR_SSL, "the SSL certificate is invalid: %#04x - %s", ret, vrfy_buf); return GIT_ECERTIFICATE; } @@ -273,18 +273,18 @@ int mbedtls_certificate(git_cert **out, git_stream *stream) const mbedtls_x509_crt *cert = mbedtls_ssl_get_peer_cert(st->ssl); if (!cert) { - giterr_set(GITERR_SSL, "the server did not provide a certificate"); + git_error_set(GIT_ERROR_SSL, "the server did not provide a certificate"); return -1; } /* Retrieve the length of the certificate first */ if (cert->raw.len == 0) { - giterr_set(GITERR_NET, "failed to retrieve certificate information"); + git_error_set(GIT_ERROR_NET, "failed to retrieve certificate information"); return -1; } encoded_cert = git__malloc(cert->raw.len); - GITERR_CHECK_ALLOC(encoded_cert); + GIT_ERROR_CHECK_ALLOC(encoded_cert); memcpy(encoded_cert, cert->raw.p, cert->raw.len); st->cert_info.parent.cert_type = GIT_CERT_X509; @@ -369,22 +369,22 @@ static int mbedtls_stream_wrap( int error; st = git__calloc(1, sizeof(mbedtls_stream)); - GITERR_CHECK_ALLOC(st); + GIT_ERROR_CHECK_ALLOC(st); st->io = in; st->owned = owned; st->ssl = git__malloc(sizeof(mbedtls_ssl_context)); - GITERR_CHECK_ALLOC(st->ssl); + GIT_ERROR_CHECK_ALLOC(st->ssl); mbedtls_ssl_init(st->ssl); if (mbedtls_ssl_setup(st->ssl, git__ssl_conf)) { - giterr_set(GITERR_SSL, "failed to create ssl object"); + git_error_set(GIT_ERROR_SSL, "failed to create ssl object"); error = -1; goto out_err; } st->host = git__strdup(host); - GITERR_CHECK_ALLOC(st->host); + GIT_ERROR_CHECK_ALLOC(st->host); st->parent.version = GIT_STREAM_VERSION; st->parent.encrypted = 1; @@ -447,7 +447,7 @@ int git_mbedtls__set_cert_location(const char *path, int is_dir) assert(path != NULL); cacert = git__malloc(sizeof(mbedtls_x509_crt)); - GITERR_CHECK_ALLOC(cacert); + GIT_ERROR_CHECK_ALLOC(cacert); mbedtls_x509_crt_init(cacert); if (is_dir) { @@ -460,7 +460,7 @@ int git_mbedtls__set_cert_location(const char *path, int is_dir) mbedtls_x509_crt_free(cacert); git__free(cacert); mbedtls_strerror( ret, errbuf, 512 ); - giterr_set(GITERR_SSL, "failed to load CA certificates: %#04x - %s", ret, errbuf); + git_error_set(GIT_ERROR_SSL, "failed to load CA certificates: %#04x - %s", ret, errbuf); return -1; } diff --git a/src/streams/openssl.c b/src/streams/openssl.c index bc129217d..6f826ef5e 100644 --- a/src/streams/openssl.c +++ b/src/streams/openssl.c @@ -237,7 +237,7 @@ int git_openssl_stream_global_init(void) return 0; error: - giterr_set(GITERR_NET, "could not initialize openssl: %s", + git_error_set(GIT_ERROR_NET, "could not initialize openssl: %s", ERR_error_string(ERR_get_error(), NULL)); SSL_CTX_free(git__ssl_ctx); git__ssl_ctx = NULL; @@ -261,11 +261,11 @@ int git_openssl_set_locking(void) num_locks = CRYPTO_num_locks(); openssl_locks = git__calloc(num_locks, sizeof(git_mutex)); - GITERR_CHECK_ALLOC(openssl_locks); + GIT_ERROR_CHECK_ALLOC(openssl_locks); for (i = 0; i < num_locks; i++) { if (git_mutex_init(&openssl_locks[i]) != 0) { - giterr_set(GITERR_SSL, "failed to initialize openssl locks"); + git_error_set(GIT_ERROR_SSL, "failed to initialize openssl locks"); return -1; } } @@ -276,7 +276,7 @@ int git_openssl_set_locking(void) #elif !defined(OPENSSL_LEGACY_API) return 0; #else - giterr_set(GITERR_THREAD, "libgit2 was not built with threads"); + git_error_set(GIT_ERROR_THREAD, "libgit2 was not built with threads"); return -1; #endif } @@ -343,7 +343,7 @@ static int init_bio_method(void) { /* Set up the BIO_METHOD we use for wrapping our own stream implementations */ git_stream_bio_method = BIO_meth_new(BIO_TYPE_SOURCE_SINK | BIO_get_new_index(), "git_stream"); - GITERR_CHECK_ALLOC(git_stream_bio_method); + GIT_ERROR_CHECK_ALLOC(git_stream_bio_method); BIO_meth_set_write(git_stream_bio_method, bio_write); BIO_meth_set_read(git_stream_bio_method, bio_read); @@ -369,23 +369,23 @@ static int ssl_set_error(SSL *ssl, int error) switch (err) { case SSL_ERROR_WANT_CONNECT: case SSL_ERROR_WANT_ACCEPT: - giterr_set(GITERR_SSL, "SSL error: connection failure"); + git_error_set(GIT_ERROR_SSL, "SSL error: connection failure"); break; case SSL_ERROR_WANT_X509_LOOKUP: - giterr_set(GITERR_SSL, "SSL error: x509 error"); + git_error_set(GIT_ERROR_SSL, "SSL error: x509 error"); break; case SSL_ERROR_SYSCALL: e = ERR_get_error(); if (e > 0) { char errmsg[256]; ERR_error_string_n(e, errmsg, sizeof(errmsg)); - giterr_set(GITERR_NET, "SSL error: %s", errmsg); + git_error_set(GIT_ERROR_NET, "SSL error: %s", errmsg); break; } else if (error < 0) { - giterr_set(GITERR_OS, "SSL error: syscall failure"); + git_error_set(GIT_ERROR_OS, "SSL error: syscall failure"); break; } - giterr_set(GITERR_SSL, "SSL error: received early EOF"); + git_error_set(GIT_ERROR_SSL, "SSL error: received early EOF"); return GIT_EEOF; break; case SSL_ERROR_SSL: @@ -393,13 +393,13 @@ static int ssl_set_error(SSL *ssl, int error) char errmsg[256]; e = ERR_get_error(); ERR_error_string_n(e, errmsg, sizeof(errmsg)); - giterr_set(GITERR_SSL, "SSL error: %s", errmsg); + git_error_set(GIT_ERROR_SSL, "SSL error: %s", errmsg); break; } case SSL_ERROR_NONE: case SSL_ERROR_ZERO_RETURN: default: - giterr_set(GITERR_SSL, "SSL error: unknown error"); + git_error_set(GIT_ERROR_SSL, "SSL error: unknown error"); break; } return -1; @@ -443,7 +443,7 @@ static int verify_server_cert(SSL *ssl, const char *host) int i = -1, j, error = 0; if (SSL_get_verify_result(ssl) != X509_V_OK) { - giterr_set(GITERR_SSL, "the SSL certificate is invalid"); + git_error_set(GIT_ERROR_SSL, "the SSL certificate is invalid"); return GIT_ECERTIFICATE; } @@ -462,7 +462,7 @@ static int verify_server_cert(SSL *ssl, const char *host) cert = SSL_get_peer_certificate(ssl); if (!cert) { error = -1; - giterr_set(GITERR_SSL, "the server did not provide a certificate"); + git_error_set(GIT_ERROR_SSL, "the server did not provide a certificate"); goto cleanup; } @@ -529,7 +529,7 @@ static int verify_server_cert(SSL *ssl, const char *host) if (size > 0) { peer_cn = OPENSSL_malloc(size + 1); - GITERR_CHECK_ALLOC(peer_cn); + GIT_ERROR_CHECK_ALLOC(peer_cn); memcpy(peer_cn, ASN1_STRING_get0_data(str), size); peer_cn[size] = '\0'; } else { @@ -537,7 +537,7 @@ static int verify_server_cert(SSL *ssl, const char *host) } } else { int size = ASN1_STRING_to_UTF8(&peer_cn, str); - GITERR_CHECK_ALLOC(peer_cn); + GIT_ERROR_CHECK_ALLOC(peer_cn); if (memchr(peer_cn, '\0', size)) goto cert_fail_name; } @@ -549,7 +549,7 @@ static int verify_server_cert(SSL *ssl, const char *host) cert_fail_name: error = GIT_ECERTIFICATE; - giterr_set(GITERR_SSL, "hostname does not match certificate"); + git_error_set(GIT_ERROR_SSL, "hostname does not match certificate"); goto cleanup; on_error: @@ -584,7 +584,7 @@ int openssl_connect(git_stream *stream) return ret; bio = BIO_new(git_stream_bio_method); - GITERR_CHECK_ALLOC(bio); + GIT_ERROR_CHECK_ALLOC(bio); BIO_set_data(bio, st->io); SSL_set_bio(st->ssl, bio, bio); @@ -612,19 +612,19 @@ int openssl_certificate(git_cert **out, git_stream *stream) /* Retrieve the length of the certificate first */ len = i2d_X509(cert, NULL); if (len < 0) { - giterr_set(GITERR_NET, "failed to retrieve certificate information"); + git_error_set(GIT_ERROR_NET, "failed to retrieve certificate information"); return -1; } encoded_cert = git__malloc(len); - GITERR_CHECK_ALLOC(encoded_cert); + GIT_ERROR_CHECK_ALLOC(encoded_cert); /* i2d_X509 makes 'guard' point to just after the data */ guard = encoded_cert; len = i2d_X509(cert, &guard); if (len < 0) { git__free(encoded_cert); - giterr_set(GITERR_NET, "failed to retrieve certificate information"); + git_error_set(GIT_ERROR_NET, "failed to retrieve certificate information"); return -1; } @@ -706,20 +706,20 @@ static int openssl_stream_wrap( assert(out && in && host); st = git__calloc(1, sizeof(openssl_stream)); - GITERR_CHECK_ALLOC(st); + GIT_ERROR_CHECK_ALLOC(st); st->io = in; st->owned = owned; st->ssl = SSL_new(git__ssl_ctx); if (st->ssl == NULL) { - giterr_set(GITERR_SSL, "failed to create ssl object"); + git_error_set(GIT_ERROR_SSL, "failed to create ssl object"); git__free(st); return -1; } st->host = git__strdup(host); - GITERR_CHECK_ALLOC(st->host); + GIT_ERROR_CHECK_ALLOC(st->host); st->parent.version = GIT_STREAM_VERSION; st->parent.encrypted = 1; @@ -765,7 +765,7 @@ int git_openssl__set_cert_location(const char *file, const char *path) char errmsg[256]; ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg)); - giterr_set(GITERR_SSL, "OpenSSL error: failed to load certificates: %s", + git_error_set(GIT_ERROR_SSL, "OpenSSL error: failed to load certificates: %s", errmsg); return -1; @@ -785,7 +785,7 @@ int git_openssl_stream_global_init(void) int git_openssl_set_locking(void) { - giterr_set(GITERR_SSL, "libgit2 was not built with OpenSSL support"); + git_error_set(GIT_ERROR_SSL, "libgit2 was not built with OpenSSL support"); return -1; } diff --git a/src/streams/registry.c b/src/streams/registry.c index 02fd3491b..b6cf489a2 100644 --- a/src/streams/registry.c +++ b/src/streams/registry.c @@ -66,7 +66,7 @@ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type) } if (git_rwlock_rdlock(&stream_registry.lock) < 0) { - giterr_set(GITERR_OS, "failed to lock stream registry"); + git_error_set(GIT_ERROR_OS, "failed to lock stream registry"); return -1; } @@ -83,10 +83,10 @@ int git_stream_register(git_stream_t type, git_stream_registration *registration { assert(!registration || registration->init); - GITERR_CHECK_VERSION(registration, GIT_STREAM_VERSION, "stream_registration"); + GIT_ERROR_CHECK_VERSION(registration, GIT_STREAM_VERSION, "stream_registration"); if (git_rwlock_wrlock(&stream_registry.lock) < 0) { - giterr_set(GITERR_OS, "failed to lock stream registry"); + git_error_set(GIT_ERROR_OS, "failed to lock stream registry"); return -1; } diff --git a/src/streams/socket.c b/src/streams/socket.c index 998e2fe87..cfd183a45 100644 --- a/src/streams/socket.c +++ b/src/streams/socket.c @@ -35,16 +35,16 @@ static void net_set_error(const char *str) char * win32_error = git_win32_get_error_message(error); if (win32_error) { - giterr_set(GITERR_NET, "%s: %s", str, win32_error); + git_error_set(GIT_ERROR_NET, "%s: %s", str, win32_error); git__free(win32_error); } else { - giterr_set(GITERR_NET, "%s", str); + git_error_set(GITERR_NET, "%s", str); } } #else static void net_set_error(const char *str) { - giterr_set(GITERR_NET, "%s: %s", str, strerror(errno)); + git_error_set(GIT_ERROR_NET, "%s: %s", str, strerror(errno)); } #endif @@ -58,7 +58,7 @@ static int close_socket(GIT_SOCKET s) return -1; if (0 != WSACleanup()) { - giterr_set(GITERR_OS, "winsock cleanup failed"); + git_error_set(GIT_ERROR_OS, "winsock cleanup failed"); return -1; } @@ -83,13 +83,13 @@ int socket_connect(git_stream *stream) WSADATA wsd; if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) { - giterr_set(GITERR_OS, "winsock init failed"); + git_error_set(GIT_ERROR_OS, "winsock init failed"); return -1; } if (LOBYTE(wsd.wVersion) != 2 || HIBYTE(wsd.wVersion) != 2) { WSACleanup(); - giterr_set(GITERR_OS, "winsock init failed"); + git_error_set(GIT_ERROR_OS, "winsock init failed"); return -1; } #endif @@ -99,7 +99,7 @@ int socket_connect(git_stream *stream) hints.ai_family = AF_UNSPEC; if ((ret = p_getaddrinfo(st->host, st->port, &hints, &info)) != 0) { - giterr_set(GITERR_NET, + git_error_set(GIT_ERROR_NET, "failed to resolve address for %s: %s", st->host, p_gai_strerror(ret)); return -1; } @@ -120,7 +120,7 @@ int socket_connect(git_stream *stream) /* Oops, we couldn't connect to any address */ if (s == INVALID_SOCKET && p == NULL) { - giterr_set(GITERR_OS, "failed to connect to %s", st->host); + git_error_set(GIT_ERROR_OS, "failed to connect to %s", st->host); p_freeaddrinfo(info); return -1; } @@ -191,14 +191,14 @@ static int default_socket_stream_new( assert(out && host && port); st = git__calloc(1, sizeof(git_socket_stream)); - GITERR_CHECK_ALLOC(st); + GIT_ERROR_CHECK_ALLOC(st); st->host = git__strdup(host); - GITERR_CHECK_ALLOC(st->host); + GIT_ERROR_CHECK_ALLOC(st->host); if (port) { st->port = git__strdup(port); - GITERR_CHECK_ALLOC(st->port); + GIT_ERROR_CHECK_ALLOC(st->port); } st->parent.version = GIT_STREAM_VERSION; @@ -232,7 +232,7 @@ int git_socket_stream_new( return error; if (!init) { - giterr_set(GITERR_NET, "there is no socket stream available"); + git_error_set(GIT_ERROR_NET, "there is no socket stream available"); return -1; } diff --git a/src/streams/stransport.c b/src/streams/stransport.c index 6626e0f68..da1156ca3 100644 --- a/src/streams/stransport.c +++ b/src/streams/stransport.c @@ -22,18 +22,18 @@ static int stransport_error(OSStatus ret) CFStringRef message; if (ret == noErr || ret == errSSLClosedGraceful) { - giterr_clear(); + git_error_clear(); return 0; } #if !TARGET_OS_IPHONE message = SecCopyErrorMessageString(ret, NULL); - GITERR_CHECK_ALLOC(message); + GIT_ERROR_CHECK_ALLOC(message); - giterr_set(GITERR_NET, "SecureTransport error: %s", CFStringGetCStringPtr(message, kCFStringEncodingUTF8)); + git_error_set(GIT_ERROR_NET, "SecureTransport error: %s", CFStringGetCStringPtr(message, kCFStringEncodingUTF8)); CFRelease(message); #else - giterr_set(GITERR_NET, "SecureTransport error: OSStatus %d", (unsigned int)ret); + git_error_set(GIT_ERROR_NET, "SecureTransport error: OSStatus %d", (unsigned int)ret); GIT_UNUSED(message); #endif @@ -62,7 +62,7 @@ static int stransport_connect(git_stream *stream) ret = SSLHandshake(st->ctx); if (ret != errSSLServerAuthCompleted) { - giterr_set(GITERR_SSL, "unexpected return value from ssl handshake %d", (int)ret); + git_error_set(GIT_ERROR_SSL, "unexpected return value from ssl handshake %d", (int)ret); return -1; } @@ -78,13 +78,13 @@ static int stransport_connect(git_stream *stream) CFRelease(trust); if (sec_res == kSecTrustResultInvalid || sec_res == kSecTrustResultOtherError) { - giterr_set(GITERR_SSL, "internal security trust error"); + git_error_set(GIT_ERROR_SSL, "internal security trust error"); return -1; } if (sec_res == kSecTrustResultDeny || sec_res == kSecTrustResultRecoverableTrustFailure || sec_res == kSecTrustResultFatalTrustFailure) { - giterr_set(GITERR_SSL, "untrusted connection error"); + git_error_set(GIT_ERROR_SSL, "untrusted connection error"); return GIT_ECERTIFICATE; } @@ -112,7 +112,7 @@ static int stransport_certificate(git_cert **out, git_stream *stream) CFRelease(trust); if (st->der_data == NULL) { - giterr_set(GITERR_SSL, "retrieved invalid certificate data"); + git_error_set(GIT_ERROR_SSL, "retrieved invalid certificate data"); return -1; } @@ -254,14 +254,14 @@ static int stransport_wrap( assert(out && in && host); st = git__calloc(1, sizeof(stransport_stream)); - GITERR_CHECK_ALLOC(st); + GIT_ERROR_CHECK_ALLOC(st); st->io = in; st->owned = owned; st->ctx = SSLCreateContext(NULL, kSSLClientSide, kSSLStreamType); if (!st->ctx) { - giterr_set(GITERR_NET, "failed to create SSL context"); + git_error_set(GIT_ERROR_NET, "failed to create SSL context"); git__free(st); return -1; } diff --git a/src/streams/tls.c b/src/streams/tls.c index 0ea47fb2f..6a251717b 100644 --- a/src/streams/tls.c +++ b/src/streams/tls.c @@ -38,7 +38,7 @@ int git_tls_stream_new(git_stream **out, const char *host, const char *port) } if (!init) { - giterr_set(GITERR_SSL, "there is no TLS stream available"); + git_error_set(GIT_ERROR_SSL, "there is no TLS stream available"); return -1; } @@ -65,7 +65,7 @@ int git_tls_stream_wrap(git_stream **out, git_stream *in, const char *host) } if (!wrap) { - giterr_set(GITERR_SSL, "there is no TLS stream available"); + git_error_set(GIT_ERROR_SSL, "there is no TLS stream available"); return -1; } diff --git a/src/strmap.c b/src/strmap.c index cee7f69e5..20b14acf3 100644 --- a/src/strmap.c +++ b/src/strmap.c @@ -21,7 +21,7 @@ __KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, k int git_strmap_alloc(git_strmap **map) { if ((*map = kh_init(str)) == NULL) { - giterr_set_oom(); + git_error_set_oom(); return -1; } diff --git a/src/submodule.c b/src/submodule.c index c468a9618..e3ec88554 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -95,7 +95,7 @@ static void submodule_set_lookup_error(int error, const char *name) if (!error) return; - giterr_set(GITERR_SUBMODULE, (error == GIT_ENOTFOUND) ? + git_error_set(GIT_ERROR_SUBMODULE, (error == GIT_ENOTFOUND) ? "no submodule named '%s'" : "submodule '%s' has not been added yet", name); } @@ -114,7 +114,7 @@ static int find_by_path(const git_config_entry *entry, void *payload) fdot = strchr(entry->name, '.'); ldot = strrchr(entry->name, '.'); data->name = git__strndup(fdot + 1, ldot - fdot - 1); - GITERR_CHECK_ALLOC(data->name); + GIT_ERROR_CHECK_ALLOC(data->name); } return 0; @@ -136,7 +136,7 @@ static int is_path_occupied(bool *occupied, git_repository *repo, const char *pa if ((error = git_index_find(NULL, index, path)) != GIT_ENOTFOUND) { if (!error) { - giterr_set(GITERR_SUBMODULE, + git_error_set(GIT_ERROR_SUBMODULE, "File '%s' already exists in the index", path); *occupied = true; } @@ -151,7 +151,7 @@ static int is_path_occupied(bool *occupied, git_repository *repo, const char *pa if ((error = git_index_find_prefix(NULL, index, dir.ptr)) != GIT_ENOTFOUND) { if (!error) { - giterr_set(GITERR_SUBMODULE, + git_error_set(GIT_ERROR_SUBMODULE, "Directory '%s' already exists in the index", path); *occupied = true; } @@ -214,7 +214,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf ldot = strrchr(entry->name, '.'); if (git_strmap_exists(names, entry->value)) { - giterr_set(GITERR_SUBMODULE, + git_error_set(GIT_ERROR_SUBMODULE, "duplicated submodule path '%s'", entry->value); error = -1; goto out; @@ -232,7 +232,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf git_strmap_insert(names, git__strdup(entry->value), git_buf_detach(&buf), &rval); if (rval < 0) { - giterr_set(GITERR_NOMEMORY, "error inserting submodule into hash table"); + git_error_set(GIT_ERROR_NOMEMORY, "error inserting submodule into hash table"); error = -1; goto out; } @@ -262,7 +262,7 @@ int git_submodule_lookup( assert(repo && name); if (repo->is_bare) { - giterr_set(GITERR_SUBMODULE, "cannot get submodules without a working tree"); + git_error_set(GIT_ERROR_SUBMODULE, "cannot get submodules without a working tree"); return -1; } @@ -551,9 +551,9 @@ int git_submodule__map(git_repository *repo, git_strmap *map) /* get sources that we will need to check */ if (git_repository_index(&idx, repo) < 0) - giterr_clear(); + git_error_clear(); if (git_repository_head_tree(&head, repo) < 0) - giterr_clear(); + git_error_clear(); wd = git_repository_workdir(repo); if (wd && (error = git_buf_joinpath(&path, wd, GIT_MODULES_FILE)) < 0) @@ -614,7 +614,7 @@ int git_submodule_foreach( size_t i; if (repo->is_bare) { - giterr_set(GITERR_SUBMODULE, "cannot get submodules without a working tree"); + git_error_set(GIT_ERROR_SUBMODULE, "cannot get submodules without a working tree"); return -1; } @@ -641,7 +641,7 @@ int git_submodule_foreach( git_vector_foreach(&snapshot, i, sm) { if ((error = callback(sm, sm->name, payload)) != 0) { - giterr_set_after_callback(error); + git_error_set_after_callback(error); break; } } @@ -730,9 +730,9 @@ int git_submodule_add_setup( /* see if there is already an entry for this submodule */ if (git_submodule_lookup(NULL, repo, path) < 0) - giterr_clear(); + git_error_clear(); else { - giterr_set(GITERR_SUBMODULE, + git_error_set(GIT_ERROR_SUBMODULE, "attempt to add submodule '%s' that already exists", path); return GIT_EEXISTS; } @@ -743,7 +743,7 @@ int git_submodule_add_setup( path += strlen(git_repository_workdir(repo)); if (git_path_root(path) >= 0) { - giterr_set(GITERR_SUBMODULE, "submodule path must be a relative path"); + git_error_set(GIT_ERROR_SUBMODULE, "submodule path must be a relative path"); error = -1; goto cleanup; } @@ -759,7 +759,7 @@ int git_submodule_add_setup( /* update .gitmodules */ if (!(mods = open_gitmodules(repo, GITMODULES_CREATE))) { - giterr_set(GITERR_SUBMODULE, + git_error_set(GIT_ERROR_SUBMODULE, "adding submodules to a bare repository is not supported"); return -1; } @@ -880,7 +880,7 @@ int git_submodule_add_to_index(git_submodule *sm, int write_index) /* read stat information for submodule working directory */ if (p_stat(path.ptr, &st) < 0) { - giterr_set(GITERR_SUBMODULE, + git_error_set(GIT_ERROR_SUBMODULE, "cannot add submodule without working directory"); error = -1; goto cleanup; @@ -893,7 +893,7 @@ int git_submodule_add_to_index(git_submodule *sm, int write_index) /* calling git_submodule_open will have set sm->wd_oid if possible */ if ((sm->flags & GIT_SUBMODULE_STATUS__WD_OID_VALID) == 0) { - giterr_set(GITERR_SUBMODULE, + git_error_set(GIT_ERROR_SUBMODULE, "cannot add submodule without HEAD to index"); error = -1; goto cleanup; @@ -984,7 +984,7 @@ int git_submodule_resolve_url(git_buf *out, git_repository *repo, const char *ur } else if (strchr(url, ':') != NULL || url[0] == '/') { error = git_buf_sets(out, url); } else { - giterr_set(GITERR_SUBMODULE, "invalid format for submodule URL"); + git_error_set(GIT_ERROR_SUBMODULE, "invalid format for submodule URL"); error = -1; } @@ -1023,7 +1023,7 @@ static int write_mapped_var(git_repository *repo, const char *name, git_cvar_map const char *val; if (git_config_lookup_map_enum(&type, &val, maps, nmaps, ival) < 0) { - giterr_set(GITERR_SUBMODULE, "invalid value for %s", var); + git_error_set(GIT_ERROR_SUBMODULE, "invalid value for %s", var); return -1; } @@ -1086,7 +1086,7 @@ const git_oid *git_submodule_wd_id(git_submodule *submodule) if (!git_submodule_open_bare(&subrepo, submodule)) git_repository_free(subrepo); else - giterr_clear(); + git_error_clear(); } if (submodule->flags & GIT_SUBMODULE_STATUS__WD_OID_VALID) @@ -1227,7 +1227,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio if (_update_options) memcpy(&update_options, _update_options, sizeof(git_submodule_update_options)); - GITERR_CHECK_VERSION(&update_options, GIT_SUBMODULE_UPDATE_OPTIONS_VERSION, "git_submodule_update_options"); + GIT_ERROR_CHECK_VERSION(&update_options, GIT_SUBMODULE_UPDATE_OPTIONS_VERSION, "git_submodule_update_options"); /* Copy over the remote callbacks */ memcpy(&clone_options.fetch_opts, &update_options.fetch_opts, sizeof(git_fetch_options)); @@ -1258,7 +1258,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio goto done; if (!init) { - giterr_set(GITERR_SUBMODULE, "submodule is not initialized"); + git_error_set(GIT_ERROR_SUBMODULE, "submodule is not initialized"); error = GIT_ERROR; goto done; } @@ -1302,7 +1302,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio goto done; if ((oid = git_submodule_index_id(sm)) == NULL) { - giterr_set(GITERR_SUBMODULE, "could not get ID of submodule in index"); + git_error_set(GIT_ERROR_SUBMODULE, "could not get ID of submodule in index"); error = -1; goto done; } @@ -1346,7 +1346,7 @@ int git_submodule_init(git_submodule *sm, int overwrite) git_config *cfg = NULL; if (!sm->url) { - giterr_set(GITERR_SUBMODULE, + git_error_set(GIT_ERROR_SUBMODULE, "no URL configured for submodule '%s'", sm->name); return -1; } @@ -1390,7 +1390,7 @@ int git_submodule_sync(git_submodule *sm) git_repository *smrepo = NULL; if (!sm->url) { - giterr_set(GITERR_SUBMODULE, + git_error_set(GIT_ERROR_SUBMODULE, "no URL configured for submodule '%s'", sm->name); return -1; } @@ -1412,7 +1412,7 @@ int git_submodule_sync(git_submodule *sm) if ((error = git_repository_config__weakptr(&cfg, smrepo)) < 0) /* return error from reading submodule config */; else if ((error = lookup_head_remote_key(&remote_name, smrepo)) < 0) { - giterr_clear(); + git_error_clear(); error = git_buf_sets(&key, "remote.origin.url"); } else { error = git_buf_join3( @@ -1469,7 +1469,7 @@ static int git_submodule__open( if (!git_reference_name_to_id(&sm->wd_oid, *subrepo, GIT_HEAD_FILE)) sm->flags |= GIT_SUBMODULE_STATUS__WD_OID_VALID; else - giterr_clear(); + git_error_clear(); } else if (git_path_exists(path.ptr)) { sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED | GIT_SUBMODULE_STATUS_IN_WD; @@ -1559,7 +1559,7 @@ static int submodule_update_head(git_submodule *submodule) /* if we can't look up file in current head, then done */ if (git_repository_head_tree(&head, submodule->repo) < 0 || git_tree_entry_bypath(&te, head, submodule->path) < 0) - giterr_clear(); + git_error_clear(); else submodule_update_from_head_data(submodule, te->attr, git_tree_entry_id(te)); @@ -1662,12 +1662,12 @@ int git_submodule__status( if (ign == GIT_SUBMODULE_IGNORE_DIRTY) { /* git_submodule_open_bare will load WD OID data */ if (git_submodule_open_bare(&smrepo, sm) < 0) - giterr_clear(); + git_error_clear(); else git_repository_free(smrepo); smrepo = NULL; } else if (git_submodule_open(&smrepo, sm) < 0) { - giterr_clear(); + git_error_clear(); smrepo = NULL; } @@ -1725,12 +1725,12 @@ static int submodule_alloc( git_submodule *sm; if (!name || !(namelen = strlen(name))) { - giterr_set(GITERR_SUBMODULE, "invalid submodule name"); + git_error_set(GIT_ERROR_SUBMODULE, "invalid submodule name"); return -1; } sm = git__calloc(1, sizeof(git_submodule)); - GITERR_CHECK_ALLOC(sm); + GIT_ERROR_CHECK_ALLOC(sm); sm->name = sm->path = git__strdup(name); if (!sm->name) { @@ -1776,7 +1776,7 @@ void git_submodule_free(git_submodule *sm) static int submodule_config_error(const char *property, const char *value) { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "invalid value for submodule '%s' property: '%s'", property, value); return -1; } @@ -1867,7 +1867,7 @@ static int submodule_read_config(git_submodule *sm, git_config *cfg) if (sm->path != sm->name) git__free(sm->path); sm->path = git__strdup(value); - GITERR_CHECK_ALLOC(sm->path); + GIT_ERROR_CHECK_ALLOC(sm->path); } } @@ -1880,7 +1880,7 @@ static int submodule_read_config(git_submodule *sm, git_config *cfg) if (!looks_like_command_line_option(value)) { in_config = 1; sm->url = git__strdup(value); - GITERR_CHECK_ALLOC(sm->url); + GIT_ERROR_CHECK_ALLOC(sm->url); } } else if (error != GIT_ENOTFOUND) { goto cleanup; @@ -1889,7 +1889,7 @@ static int submodule_read_config(git_submodule *sm, git_config *cfg) if ((error = get_value(&value, cfg, &key, sm->name, "branch")) == 0) { in_config = 1; sm->branch = git__strdup(value); - GITERR_CHECK_ALLOC(sm->branch); + GIT_ERROR_CHECK_ALLOC(sm->branch); } else if (error != GIT_ENOTFOUND) { goto cleanup; } @@ -2091,7 +2091,7 @@ static int lookup_head_remote_key(git_buf *remote_name, git_repository *repo) * a remote key for the local tracking branch HEAD points to. **/ if (!git_reference_is_branch(head)) { - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "HEAD does not refer to a branch."); error = GIT_ENOTFOUND; goto done; @@ -2140,8 +2140,8 @@ static int lookup_default_remote(git_remote **remote, git_repository *repo) error = git_remote_lookup(remote, repo, "origin"); if (error == GIT_ENOTFOUND) - giterr_set( - GITERR_SUBMODULE, + git_error_set( + GIT_ERROR_SUBMODULE, "cannot get default remote for submodule - no local tracking " "branch for HEAD and origin does not exist"); @@ -2160,7 +2160,7 @@ static int get_url_base(git_buf *url, git_repository *repo) } else if (error != GIT_ENOTFOUND) goto out; else - giterr_clear(); + git_error_clear(); /* if repository does not have a default remote, use workdir instead */ if (git_repository_is_worktree(repo)) { @@ -2241,11 +2241,11 @@ static void submodule_get_wd_status( /* if we don't have an unborn head, check diff with index */ if (git_repository_head_tree(&sm_head, sm_repo) < 0) - giterr_clear(); + git_error_clear(); else { /* perform head to index diff on submodule */ if (git_diff_tree_to_index(&diff, sm_repo, sm_head, index, &opt) < 0) - giterr_clear(); + git_error_clear(); else { if (git_diff_num_deltas(diff) > 0) *status |= GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED; @@ -2258,7 +2258,7 @@ static void submodule_get_wd_status( /* perform index-to-workdir diff on submodule */ if (git_diff_index_to_workdir(&diff, sm_repo, index, &opt) < 0) - giterr_clear(); + git_error_clear(); else { size_t untracked = git_diff_num_deltas_of_type(diff, GIT_DELTA_UNTRACKED); diff --git a/src/sysdir.c b/src/sysdir.c index 5b1549e69..e07ba7199 100644 --- a/src/sysdir.c +++ b/src/sysdir.c @@ -57,12 +57,12 @@ static int get_passwd_home(git_buf *out, uid_t uid) } while (error == ERANGE && buflen <= 8192); if (error) { - giterr_set(GITERR_OS, "failed to get passwd entry"); + git_error_set(GIT_ERROR_OS, "failed to get passwd entry"); goto out; } if (!pwdptr) { - giterr_set(GITERR_OS, "no passwd entry found for user"); + git_error_set(GIT_ERROR_OS, "no passwd entry found for user"); goto out; } @@ -96,7 +96,7 @@ static int git_sysdir_guess_global_dirs(git_buf *out) error = get_passwd_home(out, euid); if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = 0; } @@ -132,7 +132,7 @@ static int git_sysdir_guess_xdg_dirs(git_buf *out) } if (error == GIT_ENOTFOUND) { - giterr_clear(); + git_error_clear(); error = 0; } @@ -189,7 +189,7 @@ static int git_sysdir_check_selector(git_sysdir_t which) if (which < ARRAY_SIZE(git_sysdir__dirs)) return 0; - giterr_set(GITERR_INVALID, "config directory selector out of range"); + git_error_set(GIT_ERROR_INVALID, "config directory selector out of range"); return -1; } @@ -200,7 +200,7 @@ int git_sysdir_get(const git_buf **out, git_sysdir_t which) *out = NULL; - GITERR_CHECK_ERROR(git_sysdir_check_selector(which)); + GIT_ERROR_CHECK_ERROR(git_sysdir_check_selector(which)); *out = &git_sysdir__dirs[which].buf; return 0; @@ -213,11 +213,11 @@ int git_sysdir_get_str( { const git_buf *path = NULL; - GITERR_CHECK_ERROR(git_sysdir_check_selector(which)); - GITERR_CHECK_ERROR(git_sysdir_get(&path, which)); + GIT_ERROR_CHECK_ERROR(git_sysdir_check_selector(which)); + GIT_ERROR_CHECK_ERROR(git_sysdir_get(&path, which)); if (!out || path->size >= outlen) { - giterr_set(GITERR_NOMEMORY, "buffer is too short for the path"); + git_error_set(GIT_ERROR_NOMEMORY, "buffer is too short for the path"); return GIT_EBUFS; } @@ -232,7 +232,7 @@ int git_sysdir_set(git_sysdir_t which, const char *search_path) const char *expand_path = NULL; git_buf merge = GIT_BUF_INIT; - GITERR_CHECK_ERROR(git_sysdir_check_selector(which)); + GIT_ERROR_CHECK_ERROR(git_sysdir_check_selector(which)); if (search_path != NULL) expand_path = strstr(search_path, PATH_MAGIC); @@ -281,7 +281,7 @@ static int git_sysdir_find_in_dirlist( const char *scan, *next = NULL; const git_buf *syspath; - GITERR_CHECK_ERROR(git_sysdir_get(&syspath, which)); + GIT_ERROR_CHECK_ERROR(git_sysdir_get(&syspath, which)); if (!syspath || !git_buf_len(syspath)) goto done; @@ -298,9 +298,9 @@ static int git_sysdir_find_in_dirlist( if (!len) continue; - GITERR_CHECK_ERROR(git_buf_set(path, scan, len)); + GIT_ERROR_CHECK_ERROR(git_buf_set(path, scan, len)); if (name) - GITERR_CHECK_ERROR(git_buf_joinpath(path, path->ptr, name)); + GIT_ERROR_CHECK_ERROR(git_buf_joinpath(path, path->ptr, name)); if (git_path_exists(path->ptr)) return 0; @@ -308,7 +308,7 @@ static int git_sysdir_find_in_dirlist( done: git_buf_dispose(path); - giterr_set(GITERR_OS, "the %s file '%s' doesn't exist", label, name); + git_error_set(GIT_ERROR_OS, "the %s file '%s' doesn't exist", label, name); return GIT_ENOTFOUND; } @@ -61,7 +61,7 @@ const char *git_tag_message(const git_tag *t) static int tag_error(const char *str) { - giterr_set(GITERR_TAG, "failed to parse tag: %s", str); + git_error_set(GIT_ERROR_TAG, "failed to parse tag: %s", str); return -1; } @@ -116,9 +116,9 @@ static int tag_parse(git_tag *tag, const char *buffer, const char *buffer_end) text_len = search - buffer; - GITERR_CHECK_ALLOC_ADD(&alloc_len, text_len, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, text_len, 1); tag->tag_name = git__malloc(alloc_len); - GITERR_CHECK_ALLOC(tag->tag_name); + GIT_ERROR_CHECK_ALLOC(tag->tag_name); memcpy(tag->tag_name, buffer, text_len); tag->tag_name[text_len] = '\0'; @@ -128,7 +128,7 @@ static int tag_parse(git_tag *tag, const char *buffer, const char *buffer_end) tag->tagger = NULL; if (buffer < buffer_end && *buffer != '\n') { tag->tagger = git__malloc(sizeof(git_signature)); - GITERR_CHECK_ALLOC(tag->tagger); + GIT_ERROR_CHECK_ALLOC(tag->tagger); if (git_signature__parse(tag->tagger, &buffer, buffer_end, "tagger ", '\n') < 0) return -1; @@ -148,9 +148,9 @@ static int tag_parse(git_tag *tag, const char *buffer, const char *buffer_end) text_len = buffer_end - ++buffer; - GITERR_CHECK_ALLOC_ADD(&alloc_len, text_len, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, text_len, 1); tag->message = git__malloc(alloc_len); - GITERR_CHECK_ALLOC(tag->message); + GIT_ERROR_CHECK_ALLOC(tag->message); memcpy(tag->message, buffer, text_len); tag->message[text_len] = '\0'; @@ -239,7 +239,7 @@ static int write_tag_annotation( on_error: git_buf_dispose(&tag); - giterr_set(GITERR_OBJECT, "failed to create tag annotation"); + git_error_set(GIT_ERROR_OBJECT, "failed to create tag annotation"); return -1; } @@ -262,7 +262,7 @@ static int git_tag_create__internal( assert(!create_tag_annotation || (tagger && message)); if (git_object_owner(target) != repo) { - giterr_set(GITERR_INVALID, "the given target does not belong to this repository"); + git_error_set(GIT_ERROR_INVALID, "the given target does not belong to this repository"); return -1; } @@ -274,7 +274,7 @@ static int git_tag_create__internal( * reference unless overwriting has explicitly been requested **/ if (error == 0 && !allow_ref_overwrite) { git_buf_dispose(&ref_name); - giterr_set(GITERR_TAG, "tag already exists"); + git_error_set(GIT_ERROR_TAG, "tag already exists"); return GIT_EEXISTS; } @@ -354,7 +354,7 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu goto on_error; if (tag.type != target_obj->cached.type) { - giterr_set(GITERR_TAG, "the type for the given target is invalid"); + git_error_set(GIT_ERROR_TAG, "the type for the given target is invalid"); goto on_error; } @@ -371,7 +371,7 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu /** Ensure the tag name doesn't conflict with an already existing * reference unless overwriting has explicitly been requested **/ if (error == 0 && !allow_ref_overwrite) { - giterr_set(GITERR_TAG, "tag already exists"); + git_error_set(GIT_ERROR_TAG, "tag already exists"); return GIT_EEXISTS; } @@ -443,7 +443,7 @@ static int tags_cb(const char *ref, void *data) if (!(error = git_reference_name_to_id(&oid, d->repo, ref))) { if ((error = d->cb(ref, &oid, d->cb_data)) != 0) - giterr_set_after_callback_function(error, "git_tag_foreach"); + git_error_set_after_callback_function(error, "git_tag_foreach"); } return error; @@ -478,7 +478,7 @@ static int tag_list_cb(const char *tag_name, git_oid *oid, void *data) p_fnmatch(filter->pattern, tag_name + GIT_REFS_TAGS_DIR_LEN, 0) == 0) { char *matched = git__strdup(tag_name + GIT_REFS_TAGS_DIR_LEN); - GITERR_CHECK_ALLOC(matched); + GIT_ERROR_CHECK_ALLOC(matched); return git_vector_insert(filter->taglist, matched); } diff --git a/src/trace.c b/src/trace.c index 080d1e891..f2f353891 100644 --- a/src/trace.c +++ b/src/trace.c @@ -31,7 +31,7 @@ int git_trace_set(git_trace_level_t level, git_trace_callback callback) GIT_UNUSED(level); GIT_UNUSED(callback); - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "this version of libgit2 was not built with tracing."); return -1; #endif diff --git a/src/transaction.c b/src/transaction.c index cc6d2b7c0..d8e38d803 100644 --- a/src/transaction.c +++ b/src/transaction.c @@ -60,7 +60,7 @@ int git_transaction_config_new(git_transaction **out, git_config *cfg) assert(out && cfg); tx = git__calloc(1, sizeof(git_transaction)); - GITERR_CHECK_ALLOC(tx); + GIT_ERROR_CHECK_ALLOC(tx); tx->type = TRANSACTION_CONFIG; tx->cfg = cfg; @@ -111,10 +111,10 @@ int git_transaction_lock_ref(git_transaction *tx, const char *refname) assert(tx && refname); node = git_pool_mallocz(&tx->pool, sizeof(transaction_node)); - GITERR_CHECK_ALLOC(node); + GIT_ERROR_CHECK_ALLOC(node); node->name = git_pool_strdup(&tx->pool, refname); - GITERR_CHECK_ALLOC(node->name); + GIT_ERROR_CHECK_ALLOC(node->name); if ((error = git_refdb_lock(&node->payload, tx->db, refname)) < 0) return error; @@ -138,7 +138,7 @@ static int find_locked(transaction_node **out, git_transaction *tx, const char * pos = git_strmap_lookup_index(tx->locks, refname); if (!git_strmap_valid_index(tx->locks, pos)) { - giterr_set(GITERR_REFERENCE, "the specified reference is not locked"); + git_error_set(GIT_ERROR_REFERENCE, "the specified reference is not locked"); return GIT_ENOTFOUND; } @@ -169,7 +169,7 @@ static int copy_common(transaction_node *node, git_transaction *tx, const git_si if (msg) { node->message = git_pool_strdup(&tx->pool, msg); - GITERR_CHECK_ALLOC(node->message); + GIT_ERROR_CHECK_ALLOC(node->message); } return 0; @@ -208,7 +208,7 @@ int git_transaction_set_symbolic_target(git_transaction *tx, const char *refname return error; node->target.symbolic = git_pool_strdup(&tx->pool, target); - GITERR_CHECK_ALLOC(node->target.symbolic); + GIT_ERROR_CHECK_ALLOC(node->target.symbolic); node->ref_type = GIT_REFERENCE_SYMBOLIC; return 0; @@ -235,18 +235,18 @@ static int dup_reflog(git_reflog **out, const git_reflog *in, git_pool *pool) size_t len, i; reflog = git_pool_mallocz(pool, sizeof(git_reflog)); - GITERR_CHECK_ALLOC(reflog); + GIT_ERROR_CHECK_ALLOC(reflog); reflog->ref_name = git_pool_strdup(pool, in->ref_name); - GITERR_CHECK_ALLOC(reflog->ref_name); + GIT_ERROR_CHECK_ALLOC(reflog->ref_name); len = in->entries.length; reflog->entries.length = len; reflog->entries.contents = git_pool_mallocz(pool, len * sizeof(void *)); - GITERR_CHECK_ALLOC(reflog->entries.contents); + GIT_ERROR_CHECK_ALLOC(reflog->entries.contents); entries = git_pool_mallocz(pool, len * sizeof(git_reflog_entry)); - GITERR_CHECK_ALLOC(entries); + GIT_ERROR_CHECK_ALLOC(entries); for (i = 0; i < len; i++) { const git_reflog_entry *src; @@ -260,7 +260,7 @@ static int dup_reflog(git_reflog **out, const git_reflog *in, git_pool *pool) git_oid_cpy(&tgt->oid_cur, &src->oid_cur); tgt->msg = git_pool_strdup(pool, src->msg); - GITERR_CHECK_ALLOC(tgt->msg); + GIT_ERROR_CHECK_ALLOC(tgt->msg); if (git_signature__pdup(&tgt->committer, src->committer, pool) < 0) return -1; @@ -300,7 +300,7 @@ static int update_target(git_refdb *db, transaction_node *node) abort(); } - GITERR_CHECK_ALLOC(ref); + GIT_ERROR_CHECK_ALLOC(ref); update_reflog = node->reflog == NULL; if (node->remove) { diff --git a/src/transport.c b/src/transport.c index bf13fe701..227ee7dee 100644 --- a/src/transport.c +++ b/src/transport.c @@ -123,7 +123,7 @@ int git_transport_new(git_transport **out, git_remote *owner, const char *url) int error; if ((error = transport_find_fn(&fn, url, ¶m)) == GIT_ENOTFOUND) { - giterr_set(GITERR_NET, "unsupported URL protocol"); + git_error_set(GIT_ERROR_NET, "unsupported URL protocol"); return -1; } else if (error < 0) return error; @@ -131,7 +131,7 @@ int git_transport_new(git_transport **out, git_remote *owner, const char *url) if ((error = fn(&transport, owner, param)) < 0) return error; - GITERR_CHECK_VERSION(transport, GIT_TRANSPORT_VERSION, "git_transport"); + GIT_ERROR_CHECK_VERSION(transport, GIT_TRANSPORT_VERSION, "git_transport"); *out = transport; @@ -162,7 +162,7 @@ int git_transport_register( } definition = git__calloc(1, sizeof(transport_definition)); - GITERR_CHECK_ALLOC(definition); + GIT_ERROR_CHECK_ALLOC(definition); definition->prefix = git_buf_detach(&prefix); definition->fn = cb; diff --git a/src/transports/auth.c b/src/transports/auth.c index dcc3e09a7..6c69282b4 100644 --- a/src/transports/auth.c +++ b/src/transports/auth.c @@ -23,7 +23,7 @@ static int basic_next_token( GIT_UNUSED(ctx); if (c->credtype != GIT_CREDTYPE_USERPASS_PLAINTEXT) { - giterr_set(GITERR_INVALID, "invalid credential type for basic auth"); + git_error_set(GIT_ERROR_INVALID, "invalid credential type for basic auth"); goto on_error; } diff --git a/src/transports/auth_negotiate.c b/src/transports/auth_negotiate.c index 173ae992e..25c865c15 100644 --- a/src/transports/auth_negotiate.c +++ b/src/transports/auth_negotiate.c @@ -44,12 +44,12 @@ static void negotiate_err_set( if (gss_display_status(&status_display, status_major, GSS_C_GSS_CODE, GSS_C_NO_OID, &context, &buffer) == GSS_S_COMPLETE) { - giterr_set(GITERR_NET, "%s: %.*s (%d.%d)", + git_error_set(GIT_ERROR_NET, "%s: %.*s (%d.%d)", message, (int)buffer.length, (const char *)buffer.value, status_major, status_minor); gss_release_buffer(&status_minor, &buffer); } else { - giterr_set(GITERR_NET, "%s: unknown negotiate error (%d.%d)", + git_error_set(GIT_ERROR_NET, "%s: unknown negotiate error (%d.%d)", message, status_major, status_minor); } } @@ -65,7 +65,7 @@ static int negotiate_set_challenge( git__free(ctx->challenge); ctx->challenge = git__strdup(challenge); - GITERR_CHECK_ALLOC(ctx->challenge); + GIT_ERROR_CHECK_ALLOC(ctx->challenge); return 0; } @@ -109,13 +109,13 @@ static int negotiate_next_token( challenge_len = ctx->challenge ? strlen(ctx->challenge) : 0; if (challenge_len < 9) { - giterr_set(GITERR_NET, "no negotiate challenge sent from server"); + git_error_set(GIT_ERROR_NET, "no negotiate challenge sent from server"); error = -1; goto done; } else if (challenge_len > 9) { if (git_buf_decode_base64(&input_buf, ctx->challenge + 10, challenge_len - 10) < 0) { - giterr_set(GITERR_NET, "invalid negotiate challenge from server"); + git_error_set(GIT_ERROR_NET, "invalid negotiate challenge from server"); error = -1; goto done; } @@ -124,7 +124,7 @@ static int negotiate_next_token( input_token.length = input_buf.size; input_token_ptr = &input_token; } else if (ctx->gss_context != GSS_C_NO_CONTEXT) { - giterr_set(GITERR_NET, "could not restart authentication"); + git_error_set(GIT_ERROR_NET, "could not restart authentication"); error = -1; goto done; } @@ -230,7 +230,7 @@ static int negotiate_init_context( gss_release_oid_set(&status_minor, &mechanism_list); if (!ctx->oid) { - giterr_set(GITERR_NET, "negotiate authentication is not supported"); + git_error_set(GIT_ERROR_NET, "negotiate authentication is not supported"); return -1; } @@ -255,7 +255,7 @@ int git_http_auth_negotiate( *out = NULL; ctx = git__calloc(1, sizeof(http_auth_negotiate_context)); - GITERR_CHECK_ALLOC(ctx); + GIT_ERROR_CHECK_ALLOC(ctx); if (negotiate_init_context(ctx, connection_data) < 0) { git__free(ctx); diff --git a/src/transports/cred.c b/src/transports/cred.c index 8055e2d65..dfacc96d3 100644 --- a/src/transports/cred.c +++ b/src/transports/cred.c @@ -88,7 +88,7 @@ int git_cred_userpass_plaintext_new( assert(cred && username && password); c = git__malloc(sizeof(git_cred_userpass_plaintext)); - GITERR_CHECK_ALLOC(c); + GIT_ERROR_CHECK_ALLOC(c); c->parent.credtype = GIT_CREDTYPE_USERPASS_PLAINTEXT; c->parent.free = plaintext_free; @@ -217,7 +217,7 @@ int git_cred_ssh_key_memory_new( GIT_UNUSED(privatekey); GIT_UNUSED(passphrase); - giterr_set(GITERR_INVALID, + git_error_set(GIT_ERROR_INVALID, "this version of libgit2 was not built with ssh memory credentials."); return -1; #endif @@ -236,25 +236,25 @@ static int git_cred_ssh_key_type_new( assert(username && cred && privatekey); c = git__calloc(1, sizeof(git_cred_ssh_key)); - GITERR_CHECK_ALLOC(c); + GIT_ERROR_CHECK_ALLOC(c); c->parent.credtype = credtype; c->parent.free = ssh_key_free; c->username = git__strdup(username); - GITERR_CHECK_ALLOC(c->username); + GIT_ERROR_CHECK_ALLOC(c->username); c->privatekey = git__strdup(privatekey); - GITERR_CHECK_ALLOC(c->privatekey); + GIT_ERROR_CHECK_ALLOC(c->privatekey); if (publickey) { c->publickey = git__strdup(publickey); - GITERR_CHECK_ALLOC(c->publickey); + GIT_ERROR_CHECK_ALLOC(c->publickey); } if (passphrase) { c->passphrase = git__strdup(passphrase); - GITERR_CHECK_ALLOC(c->passphrase); + GIT_ERROR_CHECK_ALLOC(c->passphrase); } *cred = &c->parent; @@ -272,13 +272,13 @@ int git_cred_ssh_interactive_new( assert(out && username && prompt_callback); c = git__calloc(1, sizeof(git_cred_ssh_interactive)); - GITERR_CHECK_ALLOC(c); + GIT_ERROR_CHECK_ALLOC(c); c->parent.credtype = GIT_CREDTYPE_SSH_INTERACTIVE; c->parent.free = ssh_interactive_free; c->username = git__strdup(username); - GITERR_CHECK_ALLOC(c->username); + GIT_ERROR_CHECK_ALLOC(c->username); c->prompt_callback = prompt_callback; c->payload = payload; @@ -293,13 +293,13 @@ int git_cred_ssh_key_from_agent(git_cred **cred, const char *username) { assert(username && cred); c = git__calloc(1, sizeof(git_cred_ssh_key)); - GITERR_CHECK_ALLOC(c); + GIT_ERROR_CHECK_ALLOC(c); c->parent.credtype = GIT_CREDTYPE_SSH_KEY; c->parent.free = ssh_key_free; c->username = git__strdup(username); - GITERR_CHECK_ALLOC(c->username); + GIT_ERROR_CHECK_ALLOC(c->username); c->privatekey = NULL; @@ -320,17 +320,17 @@ int git_cred_ssh_custom_new( assert(username && cred); c = git__calloc(1, sizeof(git_cred_ssh_custom)); - GITERR_CHECK_ALLOC(c); + GIT_ERROR_CHECK_ALLOC(c); c->parent.credtype = GIT_CREDTYPE_SSH_CUSTOM; c->parent.free = ssh_custom_free; c->username = git__strdup(username); - GITERR_CHECK_ALLOC(c->username); + GIT_ERROR_CHECK_ALLOC(c->username); if (publickey_len > 0) { c->publickey = git__malloc(publickey_len); - GITERR_CHECK_ALLOC(c->publickey); + GIT_ERROR_CHECK_ALLOC(c->publickey); memcpy(c->publickey, publickey, publickey_len); } @@ -350,7 +350,7 @@ int git_cred_default_new(git_cred **cred) assert(cred); c = git__calloc(1, sizeof(git_cred_default)); - GITERR_CHECK_ALLOC(c); + GIT_ERROR_CHECK_ALLOC(c); c->credtype = GIT_CREDTYPE_DEFAULT; c->free = default_free; @@ -368,10 +368,10 @@ int git_cred_username_new(git_cred **cred, const char *username) len = strlen(username); - GITERR_CHECK_ALLOC_ADD(&allocsize, sizeof(git_cred_username), len); - GITERR_CHECK_ALLOC_ADD(&allocsize, allocsize, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, sizeof(git_cred_username), len); + GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, allocsize, 1); c = git__malloc(allocsize); - GITERR_CHECK_ALLOC(c); + GIT_ERROR_CHECK_ALLOC(c); c->parent.credtype = GIT_CREDTYPE_USERNAME; c->parent.free = username_free; diff --git a/src/transports/git.c b/src/transports/git.c index 82a565fe9..b3f563d95 100644 --- a/src/transports/git.c +++ b/src/transports/git.c @@ -47,7 +47,7 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url) delim = strchr(url, '/'); if (delim == NULL) { - giterr_set(GITERR_NET, "malformed URL"); + git_error_set(GIT_ERROR_NET, "malformed URL"); return -1; } @@ -163,7 +163,7 @@ static int git_proto_stream_alloc( return -1; s = git__calloc(1, sizeof(git_proto_stream)); - GITERR_CHECK_ALLOC(s); + GIT_ERROR_CHECK_ALLOC(s); s->parent.subtransport = &t->parent; s->parent.read = git_proto_stream_read; @@ -181,7 +181,7 @@ static int git_proto_stream_alloc( if ((git_socket_stream_new(&s->io, host, port)) < 0) return -1; - GITERR_CHECK_VERSION(s->io, GIT_STREAM_VERSION, "git_stream"); + GIT_ERROR_CHECK_VERSION(s->io, GIT_STREAM_VERSION, "git_stream"); *stream = &s->parent; return 0; @@ -242,7 +242,7 @@ static int _git_uploadpack( return 0; } - giterr_set(GITERR_NET, "must call UPLOADPACK_LS before UPLOADPACK"); + git_error_set(GIT_ERROR_NET, "must call UPLOADPACK_LS before UPLOADPACK"); return -1; } @@ -298,7 +298,7 @@ static int _git_receivepack( return 0; } - giterr_set(GITERR_NET, "must call RECEIVEPACK_LS before RECEIVEPACK"); + git_error_set(GIT_ERROR_NET, "must call RECEIVEPACK_LS before RECEIVEPACK"); return -1; } @@ -358,7 +358,7 @@ int git_smart_subtransport_git(git_smart_subtransport **out, git_transport *owne return -1; t = git__calloc(1, sizeof(git_subtransport)); - GITERR_CHECK_ALLOC(t); + GIT_ERROR_CHECK_ALLOC(t); t->owner = owner; t->parent.action = _git_action; diff --git a/src/transports/http.c b/src/transports/http.c index 387754e3f..2168072f2 100644 --- a/src/transports/http.c +++ b/src/transports/http.c @@ -307,44 +307,44 @@ static int on_header_ready(http_subtransport *t) if (!strcasecmp("Content-Type", git_buf_cstr(name))) { if (t->content_type) { - giterr_set(GITERR_NET, "multiple Content-Type headers"); + git_error_set(GIT_ERROR_NET, "multiple Content-Type headers"); return -1; } t->content_type = git__strdup(git_buf_cstr(value)); - GITERR_CHECK_ALLOC(t->content_type); + GIT_ERROR_CHECK_ALLOC(t->content_type); } else if (!strcasecmp("Content-Length", git_buf_cstr(name))) { if (t->content_length) { - giterr_set(GITERR_NET, "multiple Content-Length headers"); + git_error_set(GIT_ERROR_NET, "multiple Content-Length headers"); return -1; } t->content_length = git__strdup(git_buf_cstr(value)); - GITERR_CHECK_ALLOC(t->content_length); + GIT_ERROR_CHECK_ALLOC(t->content_length); } else if (!strcasecmp("Proxy-Authenticate", git_buf_cstr(name))) { char *dup = git__strdup(git_buf_cstr(value)); - GITERR_CHECK_ALLOC(dup); + GIT_ERROR_CHECK_ALLOC(dup); if (git_vector_insert(&t->proxy.auth_challenges, dup) < 0) return -1; } else if (!strcasecmp("WWW-Authenticate", git_buf_cstr(name))) { char *dup = git__strdup(git_buf_cstr(value)); - GITERR_CHECK_ALLOC(dup); + GIT_ERROR_CHECK_ALLOC(dup); if (git_vector_insert(&t->server.auth_challenges, dup) < 0) return -1; } else if (!strcasecmp("Location", git_buf_cstr(name))) { if (t->location) { - giterr_set(GITERR_NET, "multiple Location headers"); + git_error_set(GIT_ERROR_NET, "multiple Location headers"); return -1; } t->location = git__strdup(git_buf_cstr(value)); - GITERR_CHECK_ALLOC(t->location); + GIT_ERROR_CHECK_ALLOC(t->location); } return 0; @@ -411,7 +411,7 @@ static int on_auth_required( int ret; if (!allowed_types) { - giterr_set(GITERR_NET, "%s requested authentication but did not negotiate mechanisms", type); + git_error_set(GIT_ERROR_NET, "%s requested authentication but did not negotiate mechanisms", type); t->parse_error = PARSE_ERROR_GENERIC; return t->parse_error; } @@ -430,7 +430,7 @@ static int on_auth_required( assert(*creds); if (!((*creds)->credtype & allowed_types)) { - giterr_set(GITERR_NET, "%s credential provider returned an invalid cred type", type); + git_error_set(GIT_ERROR_NET, "%s credential provider returned an invalid cred type", type); t->parse_error = PARSE_ERROR_GENERIC; return t->parse_error; } @@ -441,7 +441,7 @@ static int on_auth_required( } } - giterr_set(GITERR_NET, "%s authentication required but no callback set", + git_error_set(GIT_ERROR_NET, "%s authentication required but no callback set", type); t->parse_error = PARSE_ERROR_GENERIC; return t->parse_error; @@ -457,7 +457,7 @@ static int on_headers_complete(http_parser *parser) /* Enforce a reasonable cap on the number of replays */ if (t->replay_count++ >= GIT_HTTP_REPLAY_MAX) { - giterr_set(GITERR_NET, "too many redirects or authentication replays"); + git_error_set(GIT_ERROR_NET, "too many redirects or authentication replays"); return t->parse_error = PARSE_ERROR_GENERIC; } @@ -525,7 +525,7 @@ static int on_headers_complete(http_parser *parser) /* Check for a 200 HTTP status code. */ if (parser->status_code != 200) { - giterr_set(GITERR_NET, + git_error_set(GIT_ERROR_NET, "unexpected HTTP status code: %d", parser->status_code); return t->parse_error = PARSE_ERROR_GENERIC; @@ -533,7 +533,7 @@ static int on_headers_complete(http_parser *parser) /* The response must contain a Content-Type header. */ if (!t->content_type) { - giterr_set(GITERR_NET, "no Content-Type header in response"); + git_error_set(GIT_ERROR_NET, "no Content-Type header in response"); return t->parse_error = PARSE_ERROR_GENERIC; } @@ -552,7 +552,7 @@ static int on_headers_complete(http_parser *parser) if (strcmp(t->content_type, git_buf_cstr(&buf))) { git_buf_dispose(&buf); - giterr_set(GITERR_NET, + git_error_set(GIT_ERROR_NET, "invalid Content-Type: %s", t->content_type); return t->parse_error = PARSE_ERROR_GENERIC; @@ -588,7 +588,7 @@ static int on_body_fill_buffer(http_parser *parser, const char *str, size_t len) /* If there's no buffer set, we're explicitly ignoring the body. */ if (ctx->buffer) { if (ctx->buf_size < len) { - giterr_set(GITERR_NET, "can't fit data in the buffer"); + git_error_set(GIT_ERROR_NET, "can't fit data in the buffer"); return t->parse_error = PARSE_ERROR_GENERIC; } @@ -702,7 +702,7 @@ static int load_proxy_config(http_subtransport *t) return error; if (t->proxy.url.use_ssl) { - giterr_set(GITERR_NET, "SSL connections to proxy are not supported"); + git_error_set(GIT_ERROR_NET, "SSL connections to proxy are not supported"); return -1; } @@ -723,18 +723,18 @@ static int check_certificate( if ((error = git_stream_certificate(&cert, stream)) < 0) return error; - giterr_state_capture(&last_error, GIT_ECERTIFICATE); + git_error_state_capture(&last_error, GIT_ECERTIFICATE); error = cert_cb(cert, is_valid, url->host, cert_cb_payload); if (error == GIT_PASSTHROUGH && !is_valid) - return giterr_state_restore(&last_error); + return git_error_state_restore(&last_error); else if (error == GIT_PASSTHROUGH) error = 0; - else if (error && !giterr_last()) - giterr_set(GITERR_NET, "user rejected certificate for %s", url->host); + else if (error && !git_error_last()) + git_error_set(GIT_ERROR_NET, "user rejected certificate for %s", url->host); - giterr_state_free(&last_error); + git_error_state_free(&last_error); return error; } @@ -746,7 +746,7 @@ static int stream_connect( { int error; - GITERR_CHECK_VERSION(stream, GIT_STREAM_VERSION, "git_stream"); + GIT_ERROR_CHECK_VERSION(stream, GIT_STREAM_VERSION, "git_stream"); error = git_stream_connect(stream); @@ -786,7 +786,7 @@ static int proxy_headers_complete(http_parser *parser) /* Enforce a reasonable cap on the number of replays */ if (t->replay_count++ >= GIT_HTTP_REPLAY_MAX) { - giterr_set(GITERR_NET, "too many redirects or authentication replays"); + git_error_set(GIT_ERROR_NET, "too many redirects or authentication replays"); return t->parse_error = PARSE_ERROR_GENERIC; } @@ -816,7 +816,7 @@ static int proxy_headers_complete(http_parser *parser) proxy_auth_types); if (parser->status_code != 200) { - giterr_set(GITERR_NET, "unexpected status code from proxy: %d", + git_error_set(GIT_ERROR_NET, "unexpected status code from proxy: %d", parser->status_code); return t->parse_error = PARSE_ERROR_GENERIC; } @@ -886,7 +886,7 @@ replay: /* Ensure that we didn't get a redirect; unsupported. */ if (t->location) { - giterr_set(GITERR_NET, "proxy server sent unsupported redirect during CONNECT"); + git_error_set(GIT_ERROR_NET, "proxy server sent unsupported redirect during CONNECT"); error = -1; goto done; } @@ -901,7 +901,7 @@ replay: } if (bytes_parsed != t->parse_buffer.offset) { - giterr_set(GITERR_NET, + git_error_set(GIT_ERROR_NET, "HTTP parser error: %s", http_errno_description((enum http_errno)t->parser.http_errno)); error = -1; @@ -1128,7 +1128,7 @@ replay: return -1; if (bytes_parsed != t->parse_buffer.offset - data_offset) { - giterr_set(GITERR_NET, + git_error_set(GIT_ERROR_NET, "HTTP parser error: %s", http_errno_description((enum http_errno)t->parser.http_errno)); return -1; @@ -1224,7 +1224,7 @@ static int http_stream_write_single( assert(t->connected); if (s->sent_request) { - giterr_set(GITERR_NET, "subtransport configured for only one write"); + git_error_set(GIT_ERROR_NET, "subtransport configured for only one write"); return -1; } @@ -1272,7 +1272,7 @@ static int http_stream_alloc(http_subtransport *t, return -1; s = git__calloc(sizeof(http_stream), 1); - GITERR_CHECK_ALLOC(s); + GIT_ERROR_CHECK_ALLOC(s); s->parent.subtransport = &t->parent; s->parent.read = http_stream_read; @@ -1478,7 +1478,7 @@ int git_smart_subtransport_http(git_smart_subtransport **out, git_transport *own return -1; t = git__calloc(sizeof(http_subtransport), 1); - GITERR_CHECK_ALLOC(t); + GIT_ERROR_CHECK_ALLOC(t); t->owner = (transport_smart *)owner; t->parent.action = http_action; diff --git a/src/transports/local.c b/src/transports/local.c index b8cc950ff..b544491ef 100644 --- a/src/transports/local.c +++ b/src/transports/local.c @@ -83,7 +83,7 @@ static int add_ref(transport_local *t, const char *name) if (!strcmp(name, GIT_HEAD_FILE) && error == GIT_ENOTFOUND) { /* This is actually okay. Empty repos often have a HEAD that * points to a nonexistent "refs/heads/master". */ - giterr_clear(); + git_error_clear(); return 0; } return error; @@ -93,16 +93,16 @@ static int add_ref(transport_local *t, const char *name) git_reference_free(resolved); head = git__calloc(1, sizeof(git_remote_head)); - GITERR_CHECK_ALLOC(head); + GIT_ERROR_CHECK_ALLOC(head); head->name = git__strdup(name); - GITERR_CHECK_ALLOC(head->name); + GIT_ERROR_CHECK_ALLOC(head->name); git_oid_cpy(&head->oid, &obj_id); if (git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC) { head->symref_target = git__strdup(git_reference_symbolic_target(ref)); - GITERR_CHECK_ALLOC(head->symref_target); + GIT_ERROR_CHECK_ALLOC(head->symref_target); } git_reference_free(ref); @@ -130,7 +130,7 @@ static int add_ref(transport_local *t, const char *name) /* And if it's a tag, peel it, and add it to the list */ head = git__calloc(1, sizeof(git_remote_head)); - GITERR_CHECK_ALLOC(head); + GIT_ERROR_CHECK_ALLOC(head); if (git_buf_join(&buf, 0, name, peeled) < 0) { free_head(head); @@ -222,7 +222,7 @@ static int local_connect( free_heads(&t->refs); t->url = git__strdup(url); - GITERR_CHECK_ALLOC(t->url); + GIT_ERROR_CHECK_ALLOC(t->url); t->direction = direction; t->flags = flags; @@ -255,7 +255,7 @@ static int local_ls(const git_remote_head ***out, size_t *size, git_transport *t transport_local *t = (transport_local *)transport; if (!t->have_refs) { - giterr_set(GITERR_NET, "the transport has not yet loaded the refs"); + git_error_set(GIT_ERROR_NET, "the transport has not yet loaded the refs"); return -1; } @@ -288,7 +288,7 @@ static int local_negotiate_fetch( else if (error != GIT_ENOTFOUND) return error; else - giterr_clear(); + git_error_clear(); git_object_free(obj); } @@ -374,7 +374,7 @@ static int local_push( but we forbid all pushes just in case */ if (!remote_repo->is_bare) { error = GIT_EBAREREPO; - giterr_set(GITERR_INVALID, "local push doesn't (yet) support pushing to non-bare repos."); + git_error_set(GIT_ERROR_INVALID, "local push doesn't (yet) support pushing to non-bare repos."); goto on_error; } @@ -418,7 +418,7 @@ static int local_push( status->msg = git__strdup("Remote branch not found to delete"); break; default: - last = giterr_last(); + last = git_error_last(); if (last && last->message) status->msg = git__strdup(last->message); @@ -520,8 +520,8 @@ static int foreach_reference_cb(git_reference *reference, void *payload) error = git_revwalk_hide(walk, git_reference_target(reference)); /* The reference is in the local repository, so the target may not * exist on the remote. It also may not be a commit. */ - if (error == GIT_ENOTFOUND || error == GITERR_INVALID) { - giterr_clear(); + if (error == GIT_ENOTFOUND || error == GIT_ERROR_INVALID) { + git_error_clear(); error = 0; } @@ -718,7 +718,7 @@ int git_transport_local(git_transport **out, git_remote *owner, void *param) GIT_UNUSED(param); t = git__calloc(1, sizeof(transport_local)); - GITERR_CHECK_ALLOC(t); + GIT_ERROR_CHECK_ALLOC(t); t->parent.version = GIT_TRANSPORT_VERSION; t->parent.set_callbacks = local_set_callbacks; diff --git a/src/transports/smart.c b/src/transports/smart.c index 9fcbdcf21..fd7113c7e 100644 --- a/src/transports/smart.c +++ b/src/transports/smart.c @@ -139,11 +139,11 @@ static int git_smart__set_custom_headers( for (i = 0; i < custom_headers->count; i++) { if (is_malformed_http_header(custom_headers->strings[i])) { - giterr_set(GITERR_INVALID, "custom HTTP header '%s' is malformed", custom_headers->strings[i]); + git_error_set(GIT_ERROR_INVALID, "custom HTTP header '%s' is malformed", custom_headers->strings[i]); return -1; } if (is_forbidden_custom_header(custom_headers->strings[i])) { - giterr_set(GITERR_INVALID, "custom HTTP header '%s' is already set by libgit2", custom_headers->strings[i]); + git_error_set(GIT_ERROR_INVALID, "custom HTTP header '%s' is already set by libgit2", custom_headers->strings[i]); return -1; } } @@ -224,7 +224,7 @@ static int git_smart__connect( return -1; t->url = git__strdup(url); - GITERR_CHECK_ALLOC(t->url); + GIT_ERROR_CHECK_ALLOC(t->url); if (git_proxy_options_dup(&t->proxy, proxy) < 0) return -1; @@ -239,7 +239,7 @@ static int git_smart__connect( else if (GIT_DIRECTION_PUSH == t->direction) service = GIT_SERVICE_RECEIVEPACK_LS; else { - giterr_set(GITERR_NET, "invalid direction"); + git_error_set(GIT_ERROR_NET, "invalid direction"); return -1; } @@ -260,7 +260,7 @@ static int git_smart__connect( pkt = (git_pkt *)git_vector_get(&t->refs, 0); if (!pkt || GIT_PKT_COMMENT != pkt->type) { - giterr_set(GITERR_NET, "invalid response"); + git_error_set(GIT_ERROR_NET, "invalid response"); return -1; } else { /* Remove the comment pkt from the list */ @@ -274,7 +274,7 @@ static int git_smart__connect( pkt = (git_pkt *)git_vector_get(&t->refs, 0); if (pkt && GIT_PKT_REF != pkt->type) { - giterr_set(GITERR_NET, "invalid response"); + git_error_set(GIT_ERROR_NET, "invalid response"); return -1; } first = (git_pkt_ref *)pkt; @@ -297,7 +297,7 @@ static int git_smart__connect( /* There was no ref packet received, or the cap list was empty */ error = 0; } else { - giterr_set(GITERR_NET, "invalid response"); + git_error_set(GIT_ERROR_NET, "invalid response"); goto cleanup; } @@ -318,7 +318,7 @@ static int git_smart__ls(const git_remote_head ***out, size_t *size, git_transpo transport_smart *t = (transport_smart *)transport; if (!t->have_refs) { - giterr_set(GITERR_NET, "the transport has not yet loaded the refs"); + git_error_set(GIT_ERROR_NET, "the transport has not yet loaded the refs"); return -1; } @@ -338,7 +338,7 @@ int git_smart__negotiation_step(git_transport *transport, void *data, size_t len return -1; if (GIT_DIRECTION_FETCH != t->direction) { - giterr_set(GITERR_NET, "this operation is only valid for fetch"); + git_error_set(GIT_ERROR_NET, "this operation is only valid for fetch"); return -1; } @@ -367,7 +367,7 @@ int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream return -1; if (GIT_DIRECTION_PUSH != t->direction) { - giterr_set(GITERR_NET, "this operation is only valid for push"); + git_error_set(GIT_ERROR_NET, "this operation is only valid for push"); return -1; } @@ -516,7 +516,7 @@ int git_transport_smart(git_transport **out, git_remote *owner, void *param) return -1; t = git__calloc(1, sizeof(transport_smart)); - GITERR_CHECK_ALLOC(t); + GIT_ERROR_CHECK_ALLOC(t); t->parent.version = GIT_TRANSPORT_VERSION; t->parent.set_callbacks = git_smart__set_callbacks; diff --git a/src/transports/smart_pkt.c b/src/transports/smart_pkt.c index fb59c70ec..9bc273e0c 100644 --- a/src/transports/smart_pkt.c +++ b/src/transports/smart_pkt.c @@ -31,7 +31,7 @@ static int flush_pkt(git_pkt **out) git_pkt *pkt; pkt = git__malloc(sizeof(git_pkt)); - GITERR_CHECK_ALLOC(pkt); + GIT_ERROR_CHECK_ALLOC(pkt); pkt->type = GIT_PKT_FLUSH; *out = pkt; @@ -45,7 +45,7 @@ static int ack_pkt(git_pkt **out, const char *line, size_t len) git_pkt_ack *pkt; pkt = git__calloc(1, sizeof(git_pkt_ack)); - GITERR_CHECK_ALLOC(pkt); + GIT_ERROR_CHECK_ALLOC(pkt); pkt->type = GIT_PKT_ACK; if (git__prefixncmp(line, len, "ACK ")) @@ -77,7 +77,7 @@ static int ack_pkt(git_pkt **out, const char *line, size_t len) return 0; out_err: - giterr_set(GITERR_NET, "error parsing ACK pkt-line"); + git_error_set(GIT_ERROR_NET, "error parsing ACK pkt-line"); git__free(pkt); return -1; } @@ -87,7 +87,7 @@ static int nak_pkt(git_pkt **out) git_pkt *pkt; pkt = git__malloc(sizeof(git_pkt)); - GITERR_CHECK_ALLOC(pkt); + GIT_ERROR_CHECK_ALLOC(pkt); pkt->type = GIT_PKT_NAK; *out = pkt; @@ -100,10 +100,10 @@ static int comment_pkt(git_pkt **out, const char *line, size_t len) git_pkt_comment *pkt; size_t alloclen; - GITERR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_pkt_comment), len); - GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_pkt_comment), len); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); pkt = git__malloc(alloclen); - GITERR_CHECK_ALLOC(pkt); + GIT_ERROR_CHECK_ALLOC(pkt); pkt->type = GIT_PKT_COMMENT; memcpy(pkt->comment, line, len); @@ -125,10 +125,10 @@ static int err_pkt(git_pkt **out, const char *line, size_t len) line += 4; len -= 4; - GITERR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_pkt_progress), len); - GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_pkt_progress), len); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); pkt = git__malloc(alloclen); - GITERR_CHECK_ALLOC(pkt); + GIT_ERROR_CHECK_ALLOC(pkt); pkt->type = GIT_PKT_ERR; pkt->len = len; @@ -140,7 +140,7 @@ static int err_pkt(git_pkt **out, const char *line, size_t len) return 0; out_err: - giterr_set(GITERR_NET, "error parsing ERR pkt-line"); + git_error_set(GIT_ERROR_NET, "error parsing ERR pkt-line"); git__free(pkt); return -1; } @@ -153,9 +153,9 @@ static int data_pkt(git_pkt **out, const char *line, size_t len) line++; len--; - GITERR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_pkt_progress), len); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_pkt_progress), len); pkt = git__malloc(alloclen); - GITERR_CHECK_ALLOC(pkt); + GIT_ERROR_CHECK_ALLOC(pkt); pkt->type = GIT_PKT_DATA; pkt->len = len; @@ -174,9 +174,9 @@ static int sideband_progress_pkt(git_pkt **out, const char *line, size_t len) line++; len--; - GITERR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_pkt_progress), len); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_pkt_progress), len); pkt = git__malloc(alloclen); - GITERR_CHECK_ALLOC(pkt); + GIT_ERROR_CHECK_ALLOC(pkt); pkt->type = GIT_PKT_PROGRESS; pkt->len = len; @@ -195,10 +195,10 @@ static int sideband_error_pkt(git_pkt **out, const char *line, size_t len) line++; len--; - GITERR_CHECK_ALLOC_ADD(&alloc_len, sizeof(git_pkt_err), len); - GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, sizeof(git_pkt_err), len); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1); pkt = git__malloc(alloc_len); - GITERR_CHECK_ALLOC(pkt); + GIT_ERROR_CHECK_ALLOC(pkt); pkt->type = GIT_PKT_ERR; pkt->len = (int)len; @@ -219,7 +219,7 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len) size_t alloclen; pkt = git__calloc(1, sizeof(git_pkt_ref)); - GITERR_CHECK_ALLOC(pkt); + GIT_ERROR_CHECK_ALLOC(pkt); pkt->type = GIT_PKT_REF; if (len < GIT_OID_HEXSZ || git_oid_fromstr(&pkt->head.oid, line) < 0) @@ -238,9 +238,9 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len) if (line[len - 1] == '\n') --len; - GITERR_CHECK_ALLOC_ADD(&alloclen, len, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1); pkt->head.name = git__malloc(alloclen); - GITERR_CHECK_ALLOC(pkt->head.name); + GIT_ERROR_CHECK_ALLOC(pkt->head.name); memcpy(pkt->head.name, line, len); pkt->head.name[len] = '\0'; @@ -252,7 +252,7 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len) return 0; out_err: - giterr_set(GITERR_NET, "error parsing REF pkt-line"); + git_error_set(GIT_ERROR_NET, "error parsing REF pkt-line"); if (pkt) git__free(pkt->head.name); git__free(pkt); @@ -265,7 +265,7 @@ static int ok_pkt(git_pkt **out, const char *line, size_t len) size_t alloc_len; pkt = git__malloc(sizeof(*pkt)); - GITERR_CHECK_ALLOC(pkt); + GIT_ERROR_CHECK_ALLOC(pkt); pkt->type = GIT_PKT_OK; if (git__prefixncmp(line, len, "ok ")) @@ -276,9 +276,9 @@ static int ok_pkt(git_pkt **out, const char *line, size_t len) if (line[len - 1] == '\n') --len; - GITERR_CHECK_ALLOC_ADD(&alloc_len, len, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, len, 1); pkt->ref = git__malloc(alloc_len); - GITERR_CHECK_ALLOC(pkt->ref); + GIT_ERROR_CHECK_ALLOC(pkt->ref); memcpy(pkt->ref, line, len); pkt->ref[len] = '\0'; @@ -287,7 +287,7 @@ static int ok_pkt(git_pkt **out, const char *line, size_t len) return 0; out_err: - giterr_set(GITERR_NET, "error parsing OK pkt-line"); + git_error_set(GIT_ERROR_NET, "error parsing OK pkt-line"); git__free(pkt); return -1; } @@ -299,7 +299,7 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len) size_t alloclen; pkt = git__malloc(sizeof(*pkt)); - GITERR_CHECK_ALLOC(pkt); + GIT_ERROR_CHECK_ALLOC(pkt); pkt->ref = NULL; pkt->type = GIT_PKT_NG; @@ -314,9 +314,9 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len) goto out_err; len = ptr - line; - GITERR_CHECK_ALLOC_ADD(&alloclen, len, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1); pkt->ref = git__malloc(alloclen); - GITERR_CHECK_ALLOC(pkt->ref); + GIT_ERROR_CHECK_ALLOC(pkt->ref); memcpy(pkt->ref, line, len); pkt->ref[len] = '\0'; @@ -329,9 +329,9 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len) goto out_err; len = ptr - line; - GITERR_CHECK_ALLOC_ADD(&alloclen, len, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1); pkt->msg = git__malloc(alloclen); - GITERR_CHECK_ALLOC(pkt->msg); + GIT_ERROR_CHECK_ALLOC(pkt->msg); memcpy(pkt->msg, line, len); pkt->msg[len] = '\0'; @@ -340,7 +340,7 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len) return 0; out_err: - giterr_set(GITERR_NET, "invalid packet line"); + git_error_set(GIT_ERROR_NET, "invalid packet line"); git__free(pkt->ref); git__free(pkt); return -1; @@ -351,7 +351,7 @@ static int unpack_pkt(git_pkt **out, const char *line, size_t len) git_pkt_unpack *pkt; pkt = git__malloc(sizeof(*pkt)); - GITERR_CHECK_ALLOC(pkt); + GIT_ERROR_CHECK_ALLOC(pkt); pkt->type = GIT_PKT_UNPACK; if (!git__prefixncmp(line, len, "unpack ok")) @@ -386,7 +386,7 @@ static int parse_len(size_t *out, const char *line, size_t linelen) } } - giterr_set(GITERR_NET, "invalid hex digit in length: '%s'", num); + git_error_set(GIT_ERROR_NET, "invalid hex digit in length: '%s'", num); return -1; } } @@ -430,9 +430,9 @@ int git_pkt_parse_line( if (error == GIT_EBUFS) ; else if (!git__prefixncmp(line, linelen, "PACK")) - giterr_set(GITERR_NET, "unexpected pack file"); + git_error_set(GIT_ERROR_NET, "unexpected pack file"); else - giterr_set(GITERR_NET, "bad packet length"); + git_error_set(GIT_ERROR_NET, "bad packet length"); return error; } @@ -458,7 +458,7 @@ int git_pkt_parse_line( * line, we should return an error upon hitting one. */ if (len == PKT_LEN_SIZE) { - giterr_set_str(GITERR_NET, "Invalid empty packet"); + git_error_set_str(GIT_ERROR_NET, "Invalid empty packet"); return GIT_ERROR; } @@ -561,7 +561,7 @@ static int buffer_want_with_caps(const git_remote_head *head, transport_smart_ca git_buf_len(&str) + 1 /* LF */; if (len > 0xffff) { - giterr_set(GITERR_NET, + git_error_set(GIT_ERROR_NET, "tried to produce packet with invalid length %" PRIuZ, len); return -1; } @@ -572,7 +572,7 @@ static int buffer_want_with_caps(const git_remote_head *head, transport_smart_ca "%04xwant %s %s\n", (unsigned int)len, oid, git_buf_cstr(&str)); git_buf_dispose(&str); - GITERR_CHECK_ALLOC_BUF(buf); + GIT_ERROR_CHECK_ALLOC_BUF(buf); return 0; } diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c index 031f851d4..2d8a1d83f 100644 --- a/src/transports/smart_protocol.c +++ b/src/transports/smart_protocol.c @@ -56,7 +56,7 @@ int git_smart__store_refs(transport_smart *t, int flushes) return recvd; if (recvd == 0) { - giterr_set(GITERR_NET, "early EOF"); + git_error_set(GIT_ERROR_NET, "early EOF"); return GIT_EEOF; } @@ -65,7 +65,7 @@ int git_smart__store_refs(transport_smart *t, int flushes) gitno_consume(buf, line_end); if (pkt->type == GIT_PKT_ERR) { - giterr_set(GITERR_NET, "remote error: %s", ((git_pkt_err *)pkt)->error); + git_error_set(GIT_ERROR_NET, "remote error: %s", ((git_pkt_err *)pkt)->error); git__free(pkt); return -1; } @@ -103,14 +103,14 @@ static int append_symref(const char **out, git_vector *symrefs, const char *ptr) /* symref mapping has refspec format */ mapping = git__calloc(1, sizeof(git_refspec)); - GITERR_CHECK_ALLOC(mapping); + GIT_ERROR_CHECK_ALLOC(mapping); error = git_refspec__parse(mapping, git_buf_cstr(&buf), true); git_buf_dispose(&buf); /* if the error isn't OOM, then it's a parse error; let's use a nicer message */ if (error < 0) { - if (giterr_last()->klass != GITERR_NOMEMORY) + if (git_error_last()->klass != GIT_ERROR_NOMEMORY) goto on_invalid; git__free(mapping); @@ -124,7 +124,7 @@ static int append_symref(const char **out, git_vector *symrefs, const char *ptr) return 0; on_invalid: - giterr_set(GITERR_NET, "remote sent invalid symref"); + git_error_set(GIT_ERROR_NET, "remote sent invalid symref"); git_refspec__dispose(mapping); git__free(mapping); return -1; @@ -230,7 +230,7 @@ static int recv_pkt(git_pkt **out_pkt, git_pkt_type *out_type, gitno_buffer *buf if ((ret = gitno_recv(buf)) < 0) { return ret; } else if (ret == 0) { - giterr_set(GITERR_NET, "early EOF"); + git_error_set(GIT_ERROR_NET, "early EOF"); return GIT_EEOF; } } while (error); @@ -382,7 +382,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c i++; if (i % 20 == 0) { if (t->cancelled.val) { - giterr_set(GITERR_NET, "The fetch was cancelled by the user"); + git_error_set(GIT_ERROR_NET, "The fetch was cancelled by the user"); error = GIT_EUSER; goto on_error; } @@ -409,7 +409,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c } else if (pkt_type == GIT_PKT_NAK) { continue; } else { - giterr_set(GITERR_NET, "Unexpected pkt type"); + git_error_set(GIT_ERROR_NET, "Unexpected pkt type"); error = -1; goto on_error; } @@ -461,7 +461,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c goto on_error; if (t->cancelled.val) { - giterr_set(GITERR_NET, "The fetch was cancelled by the user"); + git_error_set(GIT_ERROR_NET, "The fetch was cancelled by the user"); error = GIT_EUSER; goto on_error; } @@ -477,7 +477,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c return error; if (pkt_type != GIT_PKT_ACK && pkt_type != GIT_PKT_NAK) { - giterr_set(GITERR_NET, "Unexpected pkt type"); + git_error_set(GIT_ERROR_NET, "Unexpected pkt type"); return -1; } } else { @@ -498,7 +498,7 @@ static int no_sideband(transport_smart *t, struct git_odb_writepack *writepack, do { if (t->cancelled.val) { - giterr_set(GITERR_NET, "The fetch was cancelled by the user"); + git_error_set(GIT_ERROR_NET, "The fetch was cancelled by the user"); return GIT_EUSER; } @@ -591,7 +591,7 @@ int git_smart__download_pack( /* Check cancellation before network call */ if (t->cancelled.val) { - giterr_clear(); + git_error_clear(); error = GIT_EUSER; goto done; } @@ -599,7 +599,7 @@ int git_smart__download_pack( if ((error = recv_pkt(&pkt, NULL, buf)) >= 0) { /* Check cancellation after network call */ if (t->cancelled.val) { - giterr_clear(); + git_error_clear(); error = GIT_EUSER; } else if (pkt->type == GIT_PKT_PROGRESS) { if (t->progress_cb) { @@ -701,7 +701,7 @@ static int add_push_report_pkt(git_push *push, git_pkt *pkt) switch (pkt->type) { case GIT_PKT_OK: status = git__calloc(1, sizeof(push_status)); - GITERR_CHECK_ALLOC(status); + GIT_ERROR_CHECK_ALLOC(status); status->msg = NULL; status->ref = git__strdup(((git_pkt_ok *)pkt)->ref); if (!status->ref || @@ -712,7 +712,7 @@ static int add_push_report_pkt(git_push *push, git_pkt *pkt) break; case GIT_PKT_NG: status = git__calloc(1, sizeof(push_status)); - GITERR_CHECK_ALLOC(status); + GIT_ERROR_CHECK_ALLOC(status); status->ref = git__strdup(((git_pkt_ng *)pkt)->ref); status->msg = git__strdup(((git_pkt_ng *)pkt)->msg); if (!status->ref || !status->msg || @@ -727,7 +727,7 @@ static int add_push_report_pkt(git_push *push, git_pkt *pkt) case GIT_PKT_FLUSH: return GIT_ITEROVER; default: - giterr_set(GITERR_NET, "report-status: protocol error"); + git_error_set(GIT_ERROR_NET, "report-status: protocol error"); return -1; } @@ -815,7 +815,7 @@ static int parse_report(transport_smart *transport, git_push *push) } if (recvd == 0) { - giterr_set(GITERR_NET, "early EOF"); + git_error_set(GIT_ERROR_NET, "early EOF"); error = GIT_EEOF; goto done; } @@ -832,7 +832,7 @@ static int parse_report(transport_smart *transport, git_push *push) error = add_push_report_sideband_pkt(push, (git_pkt_data *)pkt, &data_pkt_buf); break; case GIT_PKT_ERR: - giterr_set(GITERR_NET, "report-status: Error reported: %s", + git_error_set(GIT_ERROR_NET, "report-status: Error reported: %s", ((git_pkt_err *)pkt)->error); error = -1; break; @@ -855,7 +855,7 @@ static int parse_report(transport_smart *transport, git_push *push) if (data_pkt_buf.size > 0) { /* If there was data remaining in the pack data buffer, * then the server sent a partial pkt-line */ - giterr_set(GITERR_NET, "Incomplete pack data pkt-line"); + git_error_set(GIT_ERROR_NET, "Incomplete pack data pkt-line"); error = GIT_ERROR; } goto done; @@ -873,7 +873,7 @@ done: static int add_ref_from_push_spec(git_vector *refs, push_spec *push_spec) { git_pkt_ref *added = git__calloc(1, sizeof(git_pkt_ref)); - GITERR_CHECK_ALLOC(added); + GIT_ERROR_CHECK_ALLOC(added); added->type = GIT_PKT_REF; git_oid_cpy(&added->head.oid, &push_spec->loid); @@ -902,7 +902,7 @@ static int update_refs_from_report( /* For each push spec we sent to the server, we should have * gotten back a status packet in the push report */ if (push_specs->length != push_report->length) { - giterr_set(GITERR_NET, "report-status: protocol error"); + git_error_set(GIT_ERROR_NET, "report-status: protocol error"); return -1; } @@ -917,7 +917,7 @@ static int update_refs_from_report( /* For each push spec we sent to the server, we should have * gotten back a status packet in the push report which matches */ if (strcmp(push_spec->refspec.dst, push_status->ref)) { - giterr_set(GITERR_NET, "report-status: protocol error"); + git_error_set(GIT_ERROR_NET, "report-status: protocol error"); return -1; } } diff --git a/src/transports/ssh.c b/src/transports/ssh.c index 9e01a4aea..5a6058fb7 100644 --- a/src/transports/ssh.c +++ b/src/transports/ssh.c @@ -54,7 +54,7 @@ static void ssh_error(LIBSSH2_SESSION *session, const char *errmsg) char *ssherr; libssh2_session_last_error(session, &ssherr, NULL, 0); - giterr_set(GITERR_SSH, "%s: %s", errmsg, ssherr); + git_error_set(GIT_ERROR_SSH, "%s: %s", errmsg, ssherr); } /* @@ -85,7 +85,7 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url) done: if (!repo) { - giterr_set(GITERR_NET, "malformed git protocol URL"); + git_error_set(GIT_ERROR_NET, "malformed git protocol URL"); return -1; } @@ -151,7 +151,7 @@ static int ssh_stream_read( */ if (rc == 0) { if ((rc = libssh2_channel_read_stderr(s->channel, buffer, buf_size)) > 0) { - giterr_set(GITERR_SSH, "%*s", rc, buffer); + git_error_set(GIT_ERROR_SSH, "%*s", rc, buffer); return GIT_EEOF; } else if (rc < LIBSSH2_ERROR_NONE) { ssh_error(s->session, "SSH could not read stderr"); @@ -238,7 +238,7 @@ static int ssh_stream_alloc( assert(stream); s = git__calloc(sizeof(ssh_stream), 1); - GITERR_CHECK_ALLOC(s); + GIT_ERROR_CHECK_ALLOC(s); s->parent.subtransport = &t->parent; s->parent.read = ssh_stream_read; @@ -272,19 +272,19 @@ static int git_ssh_extract_url_parts( if (at) { start = at + 1; *username = git__substrdup(url, at - url); - GITERR_CHECK_ALLOC(*username); + GIT_ERROR_CHECK_ALLOC(*username); } else { start = url; *username = NULL; } if (colon == NULL || (colon < start)) { - giterr_set(GITERR_NET, "malformed URL"); + git_error_set(GIT_ERROR_NET, "malformed URL"); return -1; } *host = git__substrdup(start, colon - start); - GITERR_CHECK_ALLOC(*host); + GIT_ERROR_CHECK_ALLOC(*host); return 0; } @@ -350,7 +350,7 @@ static int _git_ssh_authenticate_session( int rc; do { - giterr_clear(); + git_error_clear(); switch (cred->credtype) { case GIT_CREDTYPE_USERPASS_PLAINTEXT: { git_cred_userpass_plaintext *c = (git_cred_userpass_plaintext *)cred; @@ -428,7 +428,7 @@ static int _git_ssh_authenticate_session( return GIT_EAUTH; if (rc != LIBSSH2_ERROR_NONE) { - if (!giterr_last()) + if (!git_error_last()) ssh_error(session, "Failed to authenticate SSH session"); return -1; } @@ -452,19 +452,19 @@ static int request_creds(git_cred **out, ssh_subtransport *t, const char *user, } else if (error < 0) { return error; } else if (!cred) { - giterr_set(GITERR_SSH, "callback failed to initialize SSH credentials"); + git_error_set(GIT_ERROR_SSH, "callback failed to initialize SSH credentials"); return -1; } } if (no_callback) { - giterr_set(GITERR_SSH, "authentication required but no callback set"); + git_error_set(GIT_ERROR_SSH, "authentication required but no callback set"); return -1; } if (!(cred->credtype & auth_methods)) { cred->free(cred); - giterr_set(GITERR_SSH, "callback returned unsupported credentials type"); + git_error_set(GIT_ERROR_SSH, "callback returned unsupported credentials type"); return -1; } @@ -485,7 +485,7 @@ static int _git_ssh_session_create( s = libssh2_session_init(); if (!s) { - giterr_set(GITERR_NET, "failed to initialize SSH session"); + git_error_set(GIT_ERROR_NET, "failed to initialize SSH session"); return -1; } @@ -544,7 +544,7 @@ static int _git_ssh_setup_conn( if ((error = git_ssh_extract_url_parts(&host, &user, url)) < 0) goto done; port = git__strdup(default_port); - GITERR_CHECK_ALLOC(port); + GIT_ERROR_CHECK_ALLOC(port); post_extract: if ((error = git_socket_stream_new(&s->io, host, port)) < 0 || @@ -573,21 +573,21 @@ post_extract: } if (cert.type == 0) { - giterr_set(GITERR_SSH, "unable to get the host key"); + git_error_set(GIT_ERROR_SSH, "unable to get the host key"); error = -1; goto done; } /* We don't currently trust any hostkeys */ - giterr_clear(); + git_error_clear(); cert_ptr = &cert; error = t->owner->certificate_check_cb((git_cert *) cert_ptr, 0, host, t->owner->message_cb_payload); if (error < 0 && error != GIT_PASSTHROUGH) { - if (!giterr_last()) - giterr_set(GITERR_NET, "user cancelled hostkey check"); + if (!git_error_last()) + git_error_set(GIT_ERROR_NET, "user cancelled hostkey check"); goto done; } @@ -626,7 +626,7 @@ post_extract: goto done; if (strcmp(user, git_cred__username(cred))) { - giterr_set(GITERR_SSH, "username does not match previous request"); + git_error_set(GIT_ERROR_SSH, "username does not match previous request"); error = -1; goto done; } @@ -693,7 +693,7 @@ static int ssh_uploadpack( return 0; } - giterr_set(GITERR_NET, "must call UPLOADPACK_LS before UPLOADPACK"); + git_error_set(GIT_ERROR_NET, "must call UPLOADPACK_LS before UPLOADPACK"); return -1; } @@ -720,7 +720,7 @@ static int ssh_receivepack( return 0; } - giterr_set(GITERR_NET, "must call RECEIVEPACK_LS before RECEIVEPACK"); + git_error_set(GIT_ERROR_NET, "must call RECEIVEPACK_LS before RECEIVEPACK"); return -1; } @@ -836,7 +836,7 @@ int git_smart_subtransport_ssh( GIT_UNUSED(param); t = git__calloc(sizeof(ssh_subtransport), 1); - GITERR_CHECK_ALLOC(t); + GIT_ERROR_CHECK_ALLOC(t); t->owner = (transport_smart *)owner; t->parent.action = _ssh_action; @@ -852,7 +852,7 @@ int git_smart_subtransport_ssh( assert(out); *out = NULL; - giterr_set(GITERR_INVALID, "cannot create SSH transport. Library was built without SSH support"); + git_error_set(GIT_ERROR_INVALID, "cannot create SSH transport. Library was built without SSH support"); return -1; #endif } @@ -872,7 +872,7 @@ int git_transport_ssh_with_paths(git_transport **out, git_remote *owner, void *p }; if (paths->count != 2) { - giterr_set(GITERR_SSH, "invalid ssh paths, must be two strings"); + git_error_set(GIT_ERROR_SSH, "invalid ssh paths, must be two strings"); return GIT_EINVALIDSPEC; } @@ -883,9 +883,9 @@ int git_transport_ssh_with_paths(git_transport **out, git_remote *owner, void *p t = (ssh_subtransport *) smart->wrapped; t->cmd_uploadpack = git__strdup(paths->strings[0]); - GITERR_CHECK_ALLOC(t->cmd_uploadpack); + GIT_ERROR_CHECK_ALLOC(t->cmd_uploadpack); t->cmd_receivepack = git__strdup(paths->strings[1]); - GITERR_CHECK_ALLOC(t->cmd_receivepack); + GIT_ERROR_CHECK_ALLOC(t->cmd_receivepack); *out = transport; return 0; @@ -896,7 +896,7 @@ int git_transport_ssh_with_paths(git_transport **out, git_remote *owner, void *p assert(out); *out = NULL; - giterr_set(GITERR_INVALID, "cannot create SSH transport. Library was built without SSH support"); + git_error_set(GIT_ERROR_INVALID, "cannot create SSH transport. Library was built without SSH support"); return -1; #endif } @@ -912,7 +912,7 @@ int git_transport_ssh_global_init(void) { #ifdef GIT_SSH if (libssh2_init(0) < 0) { - giterr_set(GITERR_SSH, "unable to initialize libssh2"); + git_error_set(GIT_ERROR_SSH, "unable to initialize libssh2"); return -1; } diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c index 11b4298f4..d87823298 100644 --- a/src/transports/winhttp.c +++ b/src/transports/winhttp.c @@ -126,7 +126,7 @@ static int _apply_userpass_credential(HINTERNET request, DWORD target, DWORD sch goto done; if (!WinHttpSetCredentials(request, target, scheme, user, pass, NULL)) { - giterr_set(GITERR_OS, "failed to set credentials"); + git_error_set(GIT_ERROR_OS, "failed to set credentials"); error = -1; } @@ -164,7 +164,7 @@ static int apply_userpass_credential(HINTERNET request, int mechanisms, git_cred } else if (mechanisms & GIT_WINHTTP_AUTH_BASIC) { native_scheme = WINHTTP_AUTH_SCHEME_BASIC; } else { - giterr_set(GITERR_NET, "invalid authentication scheme"); + git_error_set(GIT_ERROR_NET, "invalid authentication scheme"); return -1; } @@ -190,7 +190,7 @@ static int apply_default_credentials(HINTERNET request, int mechanisms) native_scheme = WINHTTP_AUTH_SCHEME_NEGOTIATE; if (!native_scheme) { - giterr_set(GITERR_NET, "invalid authentication scheme"); + git_error_set(GIT_ERROR_NET, "invalid authentication scheme"); return -1; } @@ -223,7 +223,7 @@ static int fallback_cred_acquire_cb( /* Convert URL to wide characters */ if (git__utf8_to_16_alloc(&wide_url, url) < 0) { - giterr_set(GITERR_OS, "failed to convert string to wide form"); + git_error_set(GIT_ERROR_OS, "failed to convert string to wide form"); return -1; } @@ -274,8 +274,8 @@ static int certificate_check(winhttp_stream *s, int valid) /* If there is no override, we should fail if WinHTTP doesn't think it's fine */ if (t->owner->certificate_check_cb == NULL && !valid) { - if (!giterr_last()) - giterr_set(GITERR_NET, "unknown certificate check failure"); + if (!git_error_last()) + git_error_set(GIT_ERROR_NET, "unknown certificate check failure"); return GIT_ECERTIFICATE; } @@ -284,11 +284,11 @@ static int certificate_check(winhttp_stream *s, int valid) return 0; if (!WinHttpQueryOption(s->request, WINHTTP_OPTION_SERVER_CERT_CONTEXT, &cert_ctx, &cert_ctx_size)) { - giterr_set(GITERR_OS, "failed to get server certificate"); + git_error_set(GIT_ERROR_OS, "failed to get server certificate"); return -1; } - giterr_clear(); + git_error_clear(); cert.parent.cert_type = GIT_CERT_X509; cert.data = cert_ctx->pbCertEncoded; cert.len = cert_ctx->cbCertEncoded; @@ -298,8 +298,8 @@ static int certificate_check(winhttp_stream *s, int valid) if (error == GIT_PASSTHROUGH) error = valid ? 0 : GIT_ECERTIFICATE; - if (error < 0 && !giterr_last()) - giterr_set(GITERR_NET, "user cancelled certificate check"); + if (error < 0 && !git_error_last()) + git_error_set(GIT_ERROR_NET, "user cancelled certificate check"); return error; } @@ -355,7 +355,7 @@ static int winhttp_stream_connect(winhttp_stream *s) /* Convert URL to wide characters */ if (git__utf8_to_16_alloc(&s->request_uri, git_buf_cstr(&buf)) < 0) { - giterr_set(GITERR_OS, "failed to convert string to wide form"); + git_error_set(GIT_ERROR_OS, "failed to convert string to wide form"); goto on_error; } @@ -370,12 +370,12 @@ static int winhttp_stream_connect(winhttp_stream *s) t->connection_data.use_ssl ? WINHTTP_FLAG_SECURE : 0); if (!s->request) { - giterr_set(GITERR_OS, "failed to open request"); + git_error_set(GIT_ERROR_OS, "failed to open request"); goto on_error; } if (!WinHttpSetTimeouts(s->request, default_timeout, default_connect_timeout, default_timeout, default_timeout)) { - giterr_set(GITERR_OS, "failed to set timeouts for WinHTTP"); + git_error_set(GIT_ERROR_OS, "failed to set timeouts for WinHTTP"); goto on_error; } @@ -387,7 +387,7 @@ static int winhttp_stream_connect(winhttp_stream *s) } else if (proxy_opts->type == GIT_PROXY_SPECIFIED) { proxy_url = git__strdup(proxy_opts->url); - GITERR_CHECK_ALLOC(proxy_url); + GIT_ERROR_CHECK_ALLOC(proxy_url); } if (proxy_url) { @@ -400,7 +400,7 @@ static int winhttp_stream_connect(winhttp_stream *s) } else if (!git__prefixcmp(proxy_url, SCHEME_HTTPS)) { t->proxy_connection_data.use_ssl = true; } else { - giterr_set(GITERR_NET, "invalid URL: '%s'", proxy_url); + git_error_set(GIT_ERROR_NET, "invalid URL: '%s'", proxy_url); return -1; } @@ -447,7 +447,7 @@ static int winhttp_stream_connect(winhttp_stream *s) WINHTTP_OPTION_PROXY, &proxy_info, sizeof(WINHTTP_PROXY_INFO))) { - giterr_set(GITERR_OS, "failed to set proxy"); + git_error_set(GIT_ERROR_OS, "failed to set proxy"); git__free(proxy_wide); goto on_error; } @@ -470,7 +470,7 @@ static int winhttp_stream_connect(winhttp_stream *s) WINHTTP_OPTION_DISABLE_FEATURE, &disable_redirects, sizeof(disable_redirects))) { - giterr_set(GITERR_OS, "failed to disable redirects"); + git_error_set(GIT_ERROR_OS, "failed to disable redirects"); goto on_error; } @@ -484,7 +484,7 @@ static int winhttp_stream_connect(winhttp_stream *s) /* Send Pragma: no-cache header */ if (!WinHttpAddRequestHeaders(s->request, pragma_nocache, (ULONG) -1L, WINHTTP_ADDREQ_FLAG_ADD)) { - giterr_set(GITERR_OS, "failed to add a header to the request"); + git_error_set(GIT_ERROR_OS, "failed to add a header to the request"); goto on_error; } @@ -497,13 +497,13 @@ static int winhttp_stream_connect(winhttp_stream *s) goto on_error; if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)) < 0) { - giterr_set(GITERR_OS, "failed to convert content-type to wide characters"); + git_error_set(GIT_ERROR_OS, "failed to convert content-type to wide characters"); goto on_error; } if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG)-1L, WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) { - giterr_set(GITERR_OS, "failed to add a header to the request"); + git_error_set(GIT_ERROR_OS, "failed to add a header to the request"); goto on_error; } @@ -514,13 +514,13 @@ static int winhttp_stream_connect(winhttp_stream *s) goto on_error; if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)) < 0) { - giterr_set(GITERR_OS, "failed to convert accept header to wide characters"); + git_error_set(GIT_ERROR_OS, "failed to convert accept header to wide characters"); goto on_error; } if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG)-1L, WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) { - giterr_set(GITERR_OS, "failed to add a header to the request"); + git_error_set(GIT_ERROR_OS, "failed to add a header to the request"); goto on_error; } } @@ -530,13 +530,13 @@ static int winhttp_stream_connect(winhttp_stream *s) git_buf_clear(&buf); git_buf_puts(&buf, t->owner->custom_headers.strings[i]); if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)) < 0) { - giterr_set(GITERR_OS, "failed to convert custom header to wide characters"); + git_error_set(GIT_ERROR_OS, "failed to convert custom header to wide characters"); goto on_error; } if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG)-1L, WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) { - giterr_set(GITERR_OS, "failed to add a header to the request"); + git_error_set(GIT_ERROR_OS, "failed to add a header to the request"); goto on_error; } } @@ -597,7 +597,7 @@ static int parse_unauthorized_response( * We can assume this was already done, since we know we are unauthorized. */ if (!WinHttpQueryAuthSchemes(request, &supported, &first, &target)) { - giterr_set(GITERR_OS, "failed to parse supported auth schemes"); + git_error_set(GIT_ERROR_OS, "failed to parse supported auth schemes"); return -1; } @@ -640,7 +640,7 @@ static int write_chunk(HINTERNET request, const char *buffer, size_t len) git_buf_cstr(&buf), (DWORD)git_buf_len(&buf), &bytes_written)) { git_buf_dispose(&buf); - giterr_set(GITERR_OS, "failed to write chunk header"); + git_error_set(GIT_ERROR_OS, "failed to write chunk header"); return -1; } @@ -650,7 +650,7 @@ static int write_chunk(HINTERNET request, const char *buffer, size_t len) if (!WinHttpWriteData(request, buffer, (DWORD)len, &bytes_written)) { - giterr_set(GITERR_OS, "failed to write chunk"); + git_error_set(GIT_ERROR_OS, "failed to write chunk"); return -1; } @@ -658,7 +658,7 @@ static int write_chunk(HINTERNET request, const char *buffer, size_t len) if (!WinHttpWriteData(request, "\r\n", 2, &bytes_written)) { - giterr_set(GITERR_OS, "failed to write chunk footer"); + git_error_set(GIT_ERROR_OS, "failed to write chunk footer"); return -1; } @@ -671,7 +671,7 @@ static int winhttp_close_connection(winhttp_subtransport *t) if (t->connection) { if (!WinHttpCloseHandle(t->connection)) { - giterr_set(GITERR_OS, "unable to close connection"); + git_error_set(GIT_ERROR_OS, "unable to close connection"); ret = -1; } @@ -680,7 +680,7 @@ static int winhttp_close_connection(winhttp_subtransport *t) if (t->session) { if (!WinHttpCloseHandle(t->session)) { - giterr_set(GITERR_OS, "unable to close session"); + git_error_set(GIT_ERROR_OS, "unable to close session"); ret = -1; } @@ -705,21 +705,21 @@ static void CALLBACK winhttp_status( status = *((DWORD *)info); if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID)) - giterr_set(GITERR_NET, "SSL certificate issued for different common name"); + git_error_set(GIT_ERROR_NET, "SSL certificate issued for different common name"); else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID)) - giterr_set(GITERR_NET, "SSL certificate has expired"); + git_error_set(GIT_ERROR_NET, "SSL certificate has expired"); else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA)) - giterr_set(GITERR_NET, "SSL certificate signed by unknown CA"); + git_error_set(GIT_ERROR_NET, "SSL certificate signed by unknown CA"); else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT)) - giterr_set(GITERR_NET, "SSL certificate is invalid"); + git_error_set(GIT_ERROR_NET, "SSL certificate is invalid"); else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED)) - giterr_set(GITERR_NET, "certificate revocation check failed"); + git_error_set(GIT_ERROR_NET, "certificate revocation check failed"); else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED)) - giterr_set(GITERR_NET, "SSL certificate was revoked"); + git_error_set(GIT_ERROR_NET, "SSL certificate was revoked"); else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR)) - giterr_set(GITERR_NET, "security libraries could not be loaded"); + git_error_set(GIT_ERROR_NET, "security libraries could not be loaded"); else - giterr_set(GITERR_NET, "unknown security error %lu", status); + git_error_set(GITERR_NET, "unknown security error %lu", status); } static int winhttp_connect( @@ -747,7 +747,7 @@ static int winhttp_connect( /* Prepare host */ if (git__utf8_to_16_alloc(&wide_host, t->connection_data.host) < 0) { - giterr_set(GITERR_OS, "unable to convert host to wide characters"); + git_error_set(GIT_ERROR_OS, "unable to convert host to wide characters"); return -1; } @@ -758,7 +758,7 @@ static int winhttp_connect( } if (git__utf8_to_16_alloc(&wide_ua, git_buf_cstr(&ua)) < 0) { - giterr_set(GITERR_OS, "unable to convert host to wide characters"); + git_error_set(GIT_ERROR_OS, "unable to convert host to wide characters"); git__free(wide_host); git_buf_dispose(&ua); return -1; @@ -775,7 +775,7 @@ static int winhttp_connect( 0); if (!t->session) { - giterr_set(GITERR_OS, "failed to init WinHTTP"); + git_error_set(GIT_ERROR_OS, "failed to init WinHTTP"); goto on_error; } @@ -790,7 +790,7 @@ static int winhttp_connect( sizeof(protocols)); if (!WinHttpSetTimeouts(t->session, default_timeout, default_connect_timeout, default_timeout, default_timeout)) { - giterr_set(GITERR_OS, "failed to set timeouts for WinHTTP"); + git_error_set(GIT_ERROR_OS, "failed to set timeouts for WinHTTP"); goto on_error; } @@ -803,12 +803,12 @@ static int winhttp_connect( 0); if (!t->connection) { - giterr_set(GITERR_OS, "failed to connect to host"); + git_error_set(GIT_ERROR_OS, "failed to connect to host"); goto on_error; } if (WinHttpSetStatusCallback(t->connection, winhttp_status, WINHTTP_CALLBACK_FLAG_SECURE_FAILURE, 0) == WINHTTP_INVALID_STATUS_CALLBACK) { - giterr_set(GITERR_OS, "failed to set status callback"); + git_error_set(GIT_ERROR_OS, "failed to set status callback"); goto on_error; } @@ -854,10 +854,10 @@ static int send_request(winhttp_stream *s, size_t len, int ignore_length) int request_failed = 0, cert_valid = 1, error = 0; DWORD ignore_flags; - giterr_clear(); + git_error_clear(); if ((error = do_send_request(s, len, ignore_length)) < 0) { if (GetLastError() != ERROR_WINHTTP_SECURE_FAILURE) { - giterr_set(GITERR_OS, "failed to send request"); + git_error_set(GIT_ERROR_OS, "failed to send request"); return -1; } @@ -865,10 +865,10 @@ static int send_request(winhttp_stream *s, size_t len, int ignore_length) cert_valid = 0; } - giterr_clear(); + git_error_clear(); if ((error = certificate_check(s, cert_valid)) < 0) { - if (!giterr_last()) - giterr_set(GITERR_OS, "user cancelled certificate check"); + if (!git_error_last()) + git_error_set(GIT_ERROR_OS, "user cancelled certificate check"); return error; } @@ -880,12 +880,12 @@ static int send_request(winhttp_stream *s, size_t len, int ignore_length) ignore_flags = no_check_cert_flags; if (!WinHttpSetOption(s->request, WINHTTP_OPTION_SECURITY_FLAGS, &ignore_flags, sizeof(ignore_flags))) { - giterr_set(GITERR_OS, "failed to set security options"); + git_error_set(GIT_ERROR_OS, "failed to set security options"); return -1; } if ((error = do_send_request(s, len, ignore_length)) < 0) - giterr_set(GITERR_OS, "failed to send request with unchecked certificate"); + git_error_set(GIT_ERROR_OS, "failed to send request with unchecked certificate"); return error; } @@ -905,7 +905,7 @@ static int winhttp_stream_read( replay: /* Enforce a reasonable cap on the number of replays */ if (replay_count++ >= GIT_HTTP_REPLAY_MAX) { - giterr_set(GITERR_NET, "too many redirects or authentication replays"); + git_error_set(GIT_ERROR_NET, "too many redirects or authentication replays"); return -1; } @@ -940,7 +940,7 @@ replay: if (!WinHttpWriteData(s->request, "0\r\n\r\n", 5, &bytes_written)) { - giterr_set(GITERR_OS, "failed to write final chunk"); + git_error_set(GIT_ERROR_OS, "failed to write final chunk"); return -1; } } @@ -951,7 +951,7 @@ replay: if (INVALID_SET_FILE_POINTER == SetFilePointer(s->post_body, 0, 0, FILE_BEGIN) && NO_ERROR != GetLastError()) { - giterr_set(GITERR_OS, "failed to reset file pointer"); + git_error_set(GIT_ERROR_OS, "failed to reset file pointer"); return -1; } @@ -965,14 +965,14 @@ replay: &bytes_read, NULL) || !bytes_read) { git__free(buffer); - giterr_set(GITERR_OS, "failed to read from temp file"); + git_error_set(GIT_ERROR_OS, "failed to read from temp file"); return -1; } if (!WinHttpWriteData(s->request, buffer, bytes_read, &bytes_written)) { git__free(buffer); - giterr_set(GITERR_OS, "failed to write data"); + git_error_set(GIT_ERROR_OS, "failed to write data"); return -1; } @@ -988,7 +988,7 @@ replay: } if (!WinHttpReceiveResponse(s->request, 0)) { - giterr_set(GITERR_OS, "failed to receive response"); + git_error_set(GIT_ERROR_OS, "failed to receive response"); return -1; } @@ -1000,7 +1000,7 @@ replay: WINHTTP_HEADER_NAME_BY_INDEX, &status_code, &status_code_length, WINHTTP_NO_HEADER_INDEX)) { - giterr_set(GITERR_OS, "failed to retrieve status code"); + git_error_set(GIT_ERROR_OS, "failed to retrieve status code"); return -1; } @@ -1030,12 +1030,12 @@ replay: &location_length, WINHTTP_NO_HEADER_INDEX) || GetLastError() != ERROR_INSUFFICIENT_BUFFER) { - giterr_set(GITERR_OS, "failed to read Location header"); + git_error_set(GIT_ERROR_OS, "failed to read Location header"); return -1; } location = git__malloc(location_length); - GITERR_CHECK_ALLOC(location); + GIT_ERROR_CHECK_ALLOC(location); if (!WinHttpQueryHeaders(s->request, WINHTTP_QUERY_LOCATION, @@ -1043,14 +1043,14 @@ replay: location, &location_length, WINHTTP_NO_HEADER_INDEX)) { - giterr_set(GITERR_OS, "failed to read Location header"); + git_error_set(GIT_ERROR_OS, "failed to read Location header"); git__free(location); return -1; } /* Convert the Location header to UTF-8 */ if (git__utf16_to_8_alloc(&location8, location) < 0) { - giterr_set(GITERR_OS, "failed to convert Location header to UTF-8"); + git_error_set(GIT_ERROR_OS, "failed to convert Location header to UTF-8"); git__free(location); return -1; } @@ -1142,7 +1142,7 @@ replay: } if (HTTP_STATUS_OK != status_code) { - giterr_set(GITERR_NET, "request failed with status code: %lu", status_code); + git_error_set(GITERR_NET, "request failed with status code: %lu", status_code); return -1; } @@ -1153,7 +1153,7 @@ replay: p_snprintf(expected_content_type_8, MAX_CONTENT_TYPE_LEN, "application/x-git-%s-advertisement", s->service); if (git__utf8_to_16(expected_content_type, MAX_CONTENT_TYPE_LEN, expected_content_type_8) < 0) { - giterr_set(GITERR_OS, "failed to convert expected content-type to wide characters"); + git_error_set(GIT_ERROR_OS, "failed to convert expected content-type to wide characters"); return -1; } @@ -1164,12 +1164,12 @@ replay: WINHTTP_HEADER_NAME_BY_INDEX, &content_type, &content_type_length, WINHTTP_NO_HEADER_INDEX)) { - giterr_set(GITERR_OS, "failed to retrieve response content-type"); + git_error_set(GIT_ERROR_OS, "failed to retrieve response content-type"); return -1; } if (wcscmp(expected_content_type, content_type)) { - giterr_set(GITERR_NET, "received unexpected content-type"); + git_error_set(GIT_ERROR_NET, "received unexpected content-type"); return -1; } @@ -1181,7 +1181,7 @@ replay: (DWORD)buf_size, &dw_bytes_read)) { - giterr_set(GITERR_OS, "failed to read data"); + git_error_set(GIT_ERROR_OS, "failed to read data"); return -1; } @@ -1204,7 +1204,7 @@ static int winhttp_stream_write_single( /* This implementation of write permits only a single call. */ if (s->sent_request) { - giterr_set(GITERR_NET, "subtransport configured for only one write"); + git_error_set(GIT_ERROR_NET, "subtransport configured for only one write"); return -1; } @@ -1217,7 +1217,7 @@ static int winhttp_stream_write_single( (LPCVOID)buffer, (DWORD)len, &bytes_written)) { - giterr_set(GITERR_OS, "failed to write data"); + git_error_set(GIT_ERROR_OS, "failed to write data"); return -1; } @@ -1235,12 +1235,12 @@ static int put_uuid_string(LPWSTR buffer, size_t buffer_len_cch) if (RPC_S_OK != status && RPC_S_UUID_LOCAL_ONLY != status && RPC_S_UUID_NO_ADDRESS != status) { - giterr_set(GITERR_NET, "unable to generate name for temp file"); + git_error_set(GIT_ERROR_NET, "unable to generate name for temp file"); return -1; } if (buffer_len_cch < UUID_LENGTH_CCH + 1) { - giterr_set(GITERR_NET, "buffer too small for name of temp file"); + git_error_set(GIT_ERROR_NET, "buffer too small for name of temp file"); return -1; } @@ -1255,7 +1255,7 @@ static int put_uuid_string(LPWSTR buffer, size_t buffer_len_cch) uuid.Data4[4], uuid.Data4[5], uuid.Data4[6], uuid.Data4[7]); if (result < UUID_LENGTH_CCH) { - giterr_set(GITERR_OS, "unable to generate name for temp file"); + git_error_set(GIT_ERROR_OS, "unable to generate name for temp file"); return -1; } @@ -1267,7 +1267,7 @@ static int get_temp_file(LPWSTR buffer, DWORD buffer_len_cch) size_t len; if (!GetTempPathW(buffer_len_cch, buffer)) { - giterr_set(GITERR_OS, "failed to get temp path"); + git_error_set(GIT_ERROR_OS, "failed to get temp path"); return -1; } @@ -1310,13 +1310,13 @@ static int winhttp_stream_write_buffered( if (INVALID_HANDLE_VALUE == s->post_body) { s->post_body = NULL; - giterr_set(GITERR_OS, "failed to create temporary file"); + git_error_set(GIT_ERROR_OS, "failed to create temporary file"); return -1; } } if (!WriteFile(s->post_body, buffer, (DWORD)len, &bytes_written, NULL)) { - giterr_set(GITERR_OS, "failed to write to temporary file"); + git_error_set(GIT_ERROR_OS, "failed to write to temporary file"); return -1; } @@ -1343,7 +1343,7 @@ static int winhttp_stream_write_chunked( if (!WinHttpAddRequestHeaders(s->request, transfer_encoding, (ULONG) -1L, WINHTTP_ADDREQ_FLAG_ADD)) { - giterr_set(GITERR_OS, "failed to add a header to the request"); + git_error_set(GIT_ERROR_OS, "failed to add a header to the request"); return -1; } @@ -1412,7 +1412,7 @@ static int winhttp_stream_alloc(winhttp_subtransport *t, winhttp_stream **stream return -1; s = git__calloc(1, sizeof(winhttp_stream)); - GITERR_CHECK_ALLOC(s); + GIT_ERROR_CHECK_ALLOC(s); s->parent.subtransport = &t->parent; s->parent.read = winhttp_stream_read; @@ -1580,7 +1580,7 @@ int git_smart_subtransport_http(git_smart_subtransport **out, git_transport *own return -1; t = git__calloc(1, sizeof(winhttp_subtransport)); - GITERR_CHECK_ALLOC(t); + GIT_ERROR_CHECK_ALLOC(t); t->owner = (transport_smart *)owner; t->parent.action = winhttp_action; diff --git a/src/tree-cache.c b/src/tree-cache.c index c33e6af9e..d3ba864eb 100644 --- a/src/tree-cache.c +++ b/src/tree-cache.c @@ -123,7 +123,7 @@ static int read_tree_internal(git_tree_cache **out, unsigned int i; tree->children = git_pool_malloc(pool, tree->children_count * sizeof(git_tree_cache *)); - GITERR_CHECK_ALLOC(tree->children); + GIT_ERROR_CHECK_ALLOC(tree->children); memset(tree->children, 0x0, tree->children_count * sizeof(git_tree_cache *)); @@ -138,7 +138,7 @@ static int read_tree_internal(git_tree_cache **out, return 0; corrupted: - giterr_set(GITERR_INDEX, "corrupted TREE extension in index"); + git_error_set(GIT_ERROR_INDEX, "corrupted TREE extension in index"); return -1; } @@ -150,7 +150,7 @@ int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer return -1; if (buffer < buffer_end) { - giterr_set(GITERR_INDEX, "corrupted TREE extension in index (unexpected trailing data)"); + git_error_set(GIT_ERROR_INDEX, "corrupted TREE extension in index (unexpected trailing data)"); return -1; } @@ -184,7 +184,7 @@ static int read_tree_recursive(git_tree_cache *cache, const git_tree *tree, git_ cache->children_count = ntrees; cache->children = git_pool_mallocz(pool, ntrees * sizeof(git_tree_cache *)); - GITERR_CHECK_ALLOC(cache->children); + GIT_ERROR_CHECK_ALLOC(cache->children); j = 0; for (i = 0; i < nentries; i++) { @@ -237,7 +237,7 @@ int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool) name_len = strlen(name); tree = git_pool_malloc(pool, sizeof(git_tree_cache) + name_len + 1); - GITERR_CHECK_ALLOC(tree); + GIT_ERROR_CHECK_ALLOC(tree); memset(tree, 0x0, sizeof(git_tree_cache)); /* NUL-terminated tree name */ diff --git a/src/tree.c b/src/tree.c index 5a3045d89..d3b11f8c7 100644 --- a/src/tree.c +++ b/src/tree.c @@ -18,7 +18,7 @@ #define MAX_FILEMODE_BYTES 6 #define TREE_ENTRY_CHECK_NAMELEN(n) \ - if (n > UINT16_MAX) { giterr_set(GITERR_INVALID, "tree entry path too long"); } + if (n > UINT16_MAX) { git_error_set(GIT_ERROR_INVALID, "tree entry path too long"); } static bool valid_filemode(const int filemode) { @@ -350,9 +350,9 @@ unsigned int git_treebuilder_entrycount(git_treebuilder *bld) static int tree_error(const char *str, const char *path) { if (path) - giterr_set(GITERR_TREE, "%s - %s", str, path); + git_error_set(GIT_ERROR_TREE, "%s - %s", str, path); else - giterr_set(GITERR_TREE, "%s", str); + git_error_set(GIT_ERROR_TREE, "%s", str); return -1; } @@ -386,7 +386,7 @@ int git_tree__parse_raw(void *_tree, const char *data, size_t size) tree->odb_obj = NULL; git_array_init_to_size(tree->entries, DEFAULT_TREE_SIZE); - GITERR_CHECK_ARRAY(tree->entries); + GIT_ERROR_CHECK_ARRAY(tree->entries); while (buffer < buffer_end) { git_tree_entry *entry; @@ -412,7 +412,7 @@ int git_tree__parse_raw(void *_tree, const char *data, size_t size) /* Allocate the entry */ { entry = git_array_alloc(tree->entries); - GITERR_CHECK_ALLOC(entry); + GIT_ERROR_CHECK_ALLOC(entry); entry->attr = attr; entry->filename_len = filename_len; @@ -503,14 +503,14 @@ static int append_entry( return error; entry = alloc_entry(filename, strlen(filename), id); - GITERR_CHECK_ALLOC(entry); + GIT_ERROR_CHECK_ALLOC(entry); entry->attr = (uint16_t)filemode; git_strmap_insert(bld->map, entry->filename, entry, &error); if (error < 0) { git_tree_entry_free(entry); - giterr_set(GITERR_TREE, "failed to append entry %s to the tree builder", filename); + git_error_set(GIT_ERROR_TREE, "failed to append entry %s to the tree builder", filename); return -1; } @@ -573,7 +573,7 @@ static int write_tree( char *subdir, *last_comp; subdir = git__strndup(entry->path, next_slash - entry->path); - GITERR_CHECK_ALLOC(subdir); + GIT_ERROR_CHECK_ALLOC(subdir); /* Write out the subtree */ written = write_tree(&sub_oid, repo, index, subdir, i, shared_buf); @@ -630,7 +630,7 @@ int git_tree__write_index( assert(oid && index && repo); if (git_index_has_conflicts(index)) { - giterr_set(GITERR_INDEX, + git_error_set(GIT_ERROR_INDEX, "cannot create a tree from a not fully merged index."); return GIT_EUNMERGED; } @@ -684,7 +684,7 @@ int git_treebuilder_new( assert(builder_p && repo); bld = git__calloc(1, sizeof(git_treebuilder)); - GITERR_CHECK_ALLOC(bld); + GIT_ERROR_CHECK_ALLOC(bld); bld->repo = repo; @@ -736,13 +736,13 @@ int git_treebuilder_insert( git_oid_cpy((git_oid *) entry->oid, id); } else { entry = alloc_entry(filename, strlen(filename), id); - GITERR_CHECK_ALLOC(entry); + GIT_ERROR_CHECK_ALLOC(entry); git_strmap_insert(bld->map, entry->filename, entry, &error); if (error < 0) { git_tree_entry_free(entry); - giterr_set(GITERR_TREE, "failed to insert %s", filename); + git_error_set(GIT_ERROR_TREE, "failed to insert %s", filename); return -1; } } @@ -910,14 +910,14 @@ int git_tree_entry_bypath( filename_len = subpath_len(path); if (filename_len == 0) { - giterr_set(GITERR_TREE, "invalid tree path given"); + git_error_set(GIT_ERROR_TREE, "invalid tree path given"); return GIT_ENOTFOUND; } entry = entry_fromname(root, path, filename_len); if (entry == NULL) { - giterr_set(GITERR_TREE, + git_error_set(GIT_ERROR_TREE, "the path '%.*s' does not exist in the given tree", (int) filename_len, path); return GIT_ENOTFOUND; } @@ -927,7 +927,7 @@ int git_tree_entry_bypath( /* If there are more components in the path... * then this entry *must* be a tree */ if (!git_tree_entry__is_tree(entry)) { - giterr_set(GITERR_TREE, + git_error_set(GIT_ERROR_TREE, "the path '%.*s' exists but is not a tree", (int) filename_len, path); return GIT_ENOTFOUND; } @@ -972,7 +972,7 @@ static int tree_walk( if (preorder) { error = callback(path->ptr, entry, payload); if (error < 0) { /* negative value stops iteration */ - giterr_set_after_callback_function(error, "git_tree_walk"); + git_error_set_after_callback_function(error, "git_tree_walk"); break; } if (error > 0) { /* positive value skips this entry */ @@ -1008,7 +1008,7 @@ static int tree_walk( if (!preorder) { error = callback(path->ptr, entry, payload); if (error < 0) { /* negative value stops iteration */ - giterr_set_after_callback_function(error, "git_tree_walk"); + git_error_set_after_callback_function(error, "git_tree_walk"); break; } error = 0; @@ -1028,7 +1028,7 @@ int git_tree_walk( git_buf root_path = GIT_BUF_INIT; if (mode != GIT_TREEWALK_POST && mode != GIT_TREEWALK_PRE) { - giterr_set(GITERR_INVALID, "invalid walking mode for tree walk"); + git_error_set(GIT_ERROR_INVALID, "invalid walking mode for tree walk"); return -1; } @@ -1052,7 +1052,7 @@ static int on_dup_entry(void **old, void *new) { GIT_UNUSED(old); GIT_UNUSED(new); - giterr_set(GITERR_TREE, "duplicate entries given for update"); + git_error_set(GIT_ERROR_TREE, "duplicate entries given for update"); return -1; } @@ -1121,14 +1121,14 @@ static int create_popped_tree(tree_stack_entry *current, tree_stack_entry *poppe git_buf_puts(component, popped->name); git__free(popped->name); - GITERR_CHECK_ALLOC(component->ptr); + GIT_ERROR_CHECK_ALLOC(component->ptr); /* Error out if this would create a D/F conflict in this update */ if (current->tree) { const git_tree_entry *to_replace; to_replace = git_tree_entry_byname(current->tree, component->ptr); if (to_replace && git_tree_entry_type(to_replace) != GIT_OBJECT_TREE) { - giterr_set(GITERR_TREE, "D/F conflict when updating tree"); + git_error_set(GIT_ERROR_TREE, "D/F conflict when updating tree"); return -1; } } @@ -1155,7 +1155,7 @@ int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseli } root_elem = git_array_alloc(stack); - GITERR_CHECK_ALLOC(root_elem); + GIT_ERROR_CHECK_ALLOC(root_elem); memset(root_elem, 0, sizeof(*root_elem)); if (baseline && (error = git_tree_dup(&root_elem->tree, baseline)) < 0) @@ -1205,13 +1205,13 @@ int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseli entry = treebuilder_get(last->bld, component.ptr); if (entry && git_tree_entry_type(entry) != GIT_OBJECT_TREE) { - giterr_set(GITERR_TREE, "D/F conflict when updating tree"); + git_error_set(GIT_ERROR_TREE, "D/F conflict when updating tree"); error = -1; goto cleanup; } new_entry = git_array_alloc(stack); - GITERR_CHECK_ALLOC(new_entry); + GIT_ERROR_CHECK_ALLOC(new_entry); memset(new_entry, 0, sizeof(*new_entry)); new_entry->tree = NULL; @@ -1222,7 +1222,7 @@ int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseli goto cleanup; new_entry->name = git__strdup(component.ptr); - GITERR_CHECK_ALLOC(new_entry->name); + GIT_ERROR_CHECK_ALLOC(new_entry->name); /* Get to the start of the next component */ path += component.size + 1; @@ -1238,7 +1238,7 @@ int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseli const git_tree_entry *e = git_treebuilder_get(last->bld, basename); if (e && git_tree_entry_type(e) != git_object__type_from_filemode(update->filemode)) { git__free(basename); - giterr_set(GITERR_TREE, "cannot replace '%s' with '%s' at '%s'", + git_error_set(GIT_ERROR_TREE, "cannot replace '%s' with '%s' at '%s'", git_object_type2string(git_tree_entry_type(e)), git_object_type2string(git_object__type_from_filemode(update->filemode)), update->path); @@ -1258,7 +1258,7 @@ int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseli break; } default: - giterr_set(GITERR_TREE, "unknown action for update"); + git_error_set(GIT_ERROR_TREE, "unknown action for update"); error = -1; goto cleanup; } diff --git a/src/unix/map.c b/src/unix/map.c index 8a07fcff9..1ebbced5c 100644 --- a/src/unix/map.c +++ b/src/unix/map.c @@ -20,7 +20,7 @@ int git__page_size(size_t *page_size) { long sc_page_size = sysconf(_SC_PAGE_SIZE); if (sc_page_size < 0) { - giterr_set(GITERR_OS, "can't determine system page size"); + git_error_set(GIT_ERROR_OS, "can't determine system page size"); return -1; } *page_size = (size_t) sc_page_size; @@ -55,7 +55,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs out->data = mmap(NULL, len, mprot, mflag, fd, offset); if (!out->data || out->data == MAP_FAILED) { - giterr_set(GITERR_OS, "failed to mmap. Could not write data"); + git_error_set(GIT_ERROR_OS, "failed to mmap. Could not write data"); return -1; } diff --git a/src/util.c b/src/util.c index 9952a60fe..984a3d780 100644 --- a/src/util.c +++ b/src/util.c @@ -49,7 +49,7 @@ int git_strarray_copy(git_strarray *tgt, const git_strarray *src) return 0; tgt->strings = git__calloc(src->count, sizeof(char *)); - GITERR_CHECK_ALLOC(tgt->strings); + GIT_ERROR_CHECK_ALLOC(tgt->strings); for (i = 0; i < src->count; ++i) { if (!src->strings[i]) @@ -164,7 +164,7 @@ int git__strntol64(int64_t *result, const char *nptr, size_t nptr_len, const cha Return: if (ndig == 0) { - giterr_set(GITERR_INVALID, "failed to convert string to long: not a number"); + git_error_set(GIT_ERROR_INVALID, "failed to convert string to long: not a number"); return -1; } @@ -172,7 +172,7 @@ Return: *endptr = p; if (ovfl) { - giterr_set(GITERR_INVALID, "failed to convert string to long: overflow error"); + git_error_set(GIT_ERROR_INVALID, "failed to convert string to long: overflow error"); return -1; } @@ -193,7 +193,7 @@ int git__strntol32(int32_t *result, const char *nptr, size_t nptr_len, const cha tmp_int = tmp_long & 0xFFFFFFFF; if (tmp_int != tmp_long) { int len = tmp_endptr - nptr; - giterr_set(GITERR_INVALID, "failed to convert: '%.*s' is too large", len, nptr); + git_error_set(GIT_ERROR_INVALID, "failed to convert: '%.*s' is too large", len, nptr); return -1; } @@ -899,7 +899,7 @@ int git__getenv(git_buf *out, const char *name) if ((value_len = GetEnvironmentVariableW(wide_name, NULL, 0)) > 0) { wide_value = git__malloc(value_len * sizeof(wchar_t)); - GITERR_CHECK_ALLOC(wide_value); + GIT_ERROR_CHECK_ALLOC(wide_value); value_len = GetEnvironmentVariableW(wide_name, wide_value, value_len); } @@ -909,7 +909,7 @@ int git__getenv(git_buf *out, const char *name) else if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) error = GIT_ENOTFOUND; else - giterr_set(GITERR_OS, "could not read environment variable '%s'", name); + git_error_set(GIT_ERROR_OS, "could not read environment variable '%s'", name); git__free(wide_name); git__free(wide_value); diff --git a/src/vector.c b/src/vector.c index 98aa7bb2f..b51e7644b 100644 --- a/src/vector.c +++ b/src/vector.c @@ -36,7 +36,7 @@ GIT_INLINE(int) resize_vector(git_vector *v, size_t new_size) return 0; new_contents = git__reallocarray(v->contents, new_size, sizeof(void *)); - GITERR_CHECK_ALLOC(new_contents); + GIT_ERROR_CHECK_ALLOC(new_contents); v->_alloc_size = new_size; v->contents = new_contents; @@ -65,9 +65,9 @@ int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp) if (src->length) { size_t bytes; - GITERR_CHECK_ALLOC_MULTIPLY(&bytes, src->length, sizeof(void *)); + GIT_ERROR_CHECK_ALLOC_MULTIPLY(&bytes, src->length, sizeof(void *)); v->contents = git__malloc(bytes); - GITERR_CHECK_ALLOC(v->contents); + GIT_ERROR_CHECK_ALLOC(v->contents); v->_alloc_size = src->length; memcpy(v->contents, src->contents, bytes); } @@ -342,7 +342,7 @@ int git_vector_insert_null(git_vector *v, size_t idx, size_t insert_len) assert(insert_len > 0 && idx <= v->length); - GITERR_CHECK_ALLOC_ADD(&new_length, v->length, insert_len); + GIT_ERROR_CHECK_ALLOC_ADD(&new_length, v->length, insert_len); if (new_length > v->_alloc_size && resize_vector(v, new_length) < 0) return -1; diff --git a/src/win32/dir.c b/src/win32/dir.c index 1d37874e4..44052caf0 100644 --- a/src/win32/dir.c +++ b/src/win32/dir.c @@ -31,7 +31,7 @@ git__DIR *git__opendir(const char *dir) new->h = FindFirstFileW(filter_w, &new->f); if (new->h == INVALID_HANDLE_VALUE) { - giterr_set(GITERR_OS, "could not open directory '%s'", dir); + git_error_set(GIT_ERROR_OS, "could not open directory '%s'", dir); git__free(new); return NULL; } @@ -56,7 +56,7 @@ int git__readdir_ext( else if (!FindNextFileW(d->h, &d->f)) { if (GetLastError() == ERROR_NO_MORE_FILES) return 0; - giterr_set(GITERR_OS, "could not read from directory '%s'", d->dir); + git_error_set(GIT_ERROR_OS, "could not read from directory '%s'", d->dir); return -1; } @@ -101,7 +101,7 @@ void git__rewinddir(git__DIR *d) d->h = FindFirstFileW(filter_w, &d->f); if (d->h == INVALID_HANDLE_VALUE) - giterr_set(GITERR_OS, "could not open directory '%s'", d->dir); + git_error_set(GIT_ERROR_OS, "could not open directory '%s'", d->dir); else d->first = 1; } diff --git a/src/win32/findfile.c b/src/win32/findfile.c index b5419bef0..7f077e154 100644 --- a/src/win32/findfile.c +++ b/src/win32/findfile.c @@ -39,7 +39,7 @@ static int win32_path_to_8(git_buf *dest, const wchar_t *src) git_win32_utf8_path utf8_path; if (git_win32_path_to_utf8(utf8_path, src) < 0) { - giterr_set(GITERR_OS, "unable to convert path to UTF-8"); + git_error_set(GIT_ERROR_OS, "unable to convert path to UTF-8"); return -1; } diff --git a/src/win32/map.c b/src/win32/map.c index 6a17aeb64..5769cb869 100644 --- a/src/win32/map.c +++ b/src/win32/map.c @@ -69,7 +69,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs if (fh == INVALID_HANDLE_VALUE) { errno = EBADF; - giterr_set(GITERR_OS, "failed to mmap. Invalid handle value"); + git_error_set(GIT_ERROR_OS, "failed to mmap. Invalid handle value"); return -1; } @@ -88,13 +88,13 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs if (page_offset != 0) { /* offset must be multiple of the allocation granularity */ errno = EINVAL; - giterr_set(GITERR_OS, "failed to mmap. Offset must be multiple of allocation granularity"); + git_error_set(GIT_ERROR_OS, "failed to mmap. Offset must be multiple of allocation granularity"); return -1; } out->fmh = CreateFileMapping(fh, NULL, fmap_prot, 0, 0, NULL); if (!out->fmh || out->fmh == INVALID_HANDLE_VALUE) { - giterr_set(GITERR_OS, "failed to mmap. Invalid handle value"); + git_error_set(GIT_ERROR_OS, "failed to mmap. Invalid handle value"); out->fmh = NULL; return -1; } @@ -105,7 +105,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs off_hi = (DWORD)(page_start >> 32); out->data = MapViewOfFile(out->fmh, view_prot, off_hi, off_low, len); if (!out->data) { - giterr_set(GITERR_OS, "failed to mmap. No data written"); + git_error_set(GIT_ERROR_OS, "failed to mmap. No data written"); CloseHandle(out->fmh); out->fmh = NULL; return -1; @@ -123,7 +123,7 @@ int p_munmap(git_map *map) if (map->data) { if (!UnmapViewOfFile(map->data)) { - giterr_set(GITERR_OS, "failed to munmap. Could not unmap view of file"); + git_error_set(GIT_ERROR_OS, "failed to munmap. Could not unmap view of file"); error = -1; } map->data = NULL; @@ -131,7 +131,7 @@ int p_munmap(git_map *map) if (map->fmh) { if (!CloseHandle(map->fmh)) { - giterr_set(GITERR_OS, "failed to munmap. Could not close handle"); + git_error_set(GIT_ERROR_OS, "failed to munmap. Could not close handle"); error = -1; } map->fmh = NULL; diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index aa9e61877..d8bbebb5d 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -532,7 +532,7 @@ int p_utimes(const char *path, const struct p_timeval times[2]) attrs_new = attrs_orig & ~FILE_ATTRIBUTE_READONLY; if (!SetFileAttributesW(wpath, attrs_new)) { - giterr_set(GITERR_OS, "failed to set attributes"); + git_error_set(GIT_ERROR_OS, "failed to set attributes"); return -1; } } @@ -852,7 +852,7 @@ int p_rename(const char *from, const char *to) int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags) { if ((size_t)((int)length) != length) - return -1; /* giterr_set will be done by caller */ + return -1; /* git_error_set will be done by caller */ return recv(socket, buffer, (int)length, flags); } @@ -860,7 +860,7 @@ int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags) int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags) { if ((size_t)((int)length) != length) - return -1; /* giterr_set will be done by caller */ + return -1; /* git_error_set will be done by caller */ return send(socket, buffer, (int)length, flags); } diff --git a/src/win32/w32_buffer.c b/src/win32/w32_buffer.c index 45c024d31..22ea9a10c 100644 --- a/src/win32/w32_buffer.c +++ b/src/win32/w32_buffer.c @@ -36,8 +36,8 @@ int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w) assert(utf8_len > 0); - GITERR_CHECK_ALLOC_ADD(&new_size, buf->size, (size_t)utf8_len); - GITERR_CHECK_ALLOC_ADD(&new_size, new_size, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, (size_t)utf8_len); + GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1); if (git_buf_grow(buf, new_size) < 0) return -1; diff --git a/src/win32/w32_crtdbg_stacktrace.c b/src/win32/w32_crtdbg_stacktrace.c index 3fcadd204..49b54f134 100644 --- a/src/win32/w32_crtdbg_stacktrace.c +++ b/src/win32/w32_crtdbg_stacktrace.c @@ -74,21 +74,21 @@ static bool g_transient_leaks_since_mark = false; /* payload for hook */ static void *crtdbg__malloc(size_t len, const char *file, int line) { void *ptr = _malloc_dbg(len, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line); - if (!ptr) giterr_set_oom(); + if (!ptr) git_error_set_oom(); return ptr; } static void *crtdbg__calloc(size_t nelem, size_t elsize, const char *file, int line) { void *ptr = _calloc_dbg(nelem, elsize, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line); - if (!ptr) giterr_set_oom(); + if (!ptr) git_error_set_oom(); return ptr; } static char *crtdbg__strdup(const char *str, const char *file, int line) { char *ptr = _strdup_dbg(str, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line); - if (!ptr) giterr_set_oom(); + if (!ptr) git_error_set_oom(); return ptr; } @@ -128,7 +128,7 @@ static char *crtdbg__substrdup(const char *start, size_t n, const char *file, in static void *crtdbg__realloc(void *ptr, size_t size, const char *file, int line) { void *new_ptr = _realloc_dbg(ptr, size, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line); - if (!new_ptr) giterr_set_oom(); + if (!new_ptr) git_error_set_oom(); return new_ptr; } @@ -347,11 +347,11 @@ int git_win32__crtdbg_stacktrace__dump( bool b_quiet = IS_BIT_SET(opt, GIT_WIN32__CRTDBG_STACKTRACE__QUIET); if (b_leaks_since_mark && b_leaks_total) { - giterr_set(GITERR_INVALID, "cannot combine LEAKS_SINCE_MARK and LEAKS_TOTAL."); + git_error_set(GIT_ERROR_INVALID, "cannot combine LEAKS_SINCE_MARK and LEAKS_TOTAL."); return GIT_ERROR; } if (!b_set_mark && !b_leaks_since_mark && !b_leaks_total) { - giterr_set(GITERR_INVALID, "nothing to do."); + git_error_set(GIT_ERROR_INVALID, "nothing to do."); return GIT_ERROR; } diff --git a/src/win32/w32_stack.c b/src/win32/w32_stack.c index b40f9d2b4..c9d6b1a28 100644 --- a/src/win32/w32_stack.c +++ b/src/win32/w32_stack.c @@ -55,7 +55,7 @@ void git_win32__stack_cleanup(void) int git_win32__stack_capture(git_win32__stack__raw_data *pdata, int skip) { if (!g_win32_stack_initialized) { - giterr_set(GITERR_INVALID, "git_win32_stack not initialized."); + git_error_set(GIT_ERROR_INVALID, "git_win32_stack not initialized."); return GIT_ERROR; } @@ -102,7 +102,7 @@ int git_win32__stack_format( int detail_len; if (!g_win32_stack_initialized) { - giterr_set(GITERR_INVALID, "git_win32_stack not initialized."); + git_error_set(GIT_ERROR_INVALID, "git_win32_stack not initialized."); return GIT_ERROR; } diff --git a/src/win32/w32_util.c b/src/win32/w32_util.c index 5996c9fb9..10e17fcd0 100644 --- a/src/win32/w32_util.c +++ b/src/win32/w32_util.c @@ -68,7 +68,7 @@ int git_win32__set_hidden(const char *path, bool hidden) newattrs = attrs & ~FILE_ATTRIBUTE_HIDDEN; if (attrs != newattrs && !SetFileAttributesW(buf, newattrs)) { - giterr_set(GITERR_OS, "failed to %s hidden bit for '%s'", + git_error_set(GIT_ERROR_OS, "failed to %s hidden bit for '%s'", hidden ? "set" : "unset", path); return -1; } diff --git a/src/win32/w32_util.h b/src/win32/w32_util.h index 5216a1396..3a7942563 100644 --- a/src/win32/w32_util.h +++ b/src/win32/w32_util.h @@ -158,7 +158,7 @@ GIT_INLINE(int) git_win32__file_attribute_to_stat( /* st_size gets the UTF-8 length of the target name, in bytes, * not counting the NULL terminator */ if ((st->st_size = git__utf16_to_8(NULL, 0, target)) < 0) { - giterr_set(GITERR_OS, "could not convert reparse point name for '%ls'", path); + git_error_set(GIT_ERROR_OS, "could not convert reparse point name for '%ls'", path); return -1; } } diff --git a/src/worktree.c b/src/worktree.c index e06cdfb8d..174a10736 100644 --- a/src/worktree.c +++ b/src/worktree.c @@ -194,7 +194,7 @@ int git_worktree_open_from_repository(git_worktree **out, git_repository *repo) int error = 0; if (!git_repository_is_worktree(repo)) { - giterr_set(GITERR_WORKTREE, "cannot open worktree of a non-worktree repo"); + git_error_set(GIT_ERROR_WORKTREE, "cannot open worktree of a non-worktree repo"); error = -1; goto out; } @@ -237,21 +237,21 @@ int git_worktree_validate(const git_worktree *wt) assert(wt); if (!is_worktree_dir(wt->gitdir_path)) { - giterr_set(GITERR_WORKTREE, + git_error_set(GIT_ERROR_WORKTREE, "Worktree gitdir ('%s') is not valid", wt->gitlink_path); return GIT_ERROR; } if (wt->parent_path && !git_path_exists(wt->parent_path)) { - giterr_set(GITERR_WORKTREE, + git_error_set(GIT_ERROR_WORKTREE, "Worktree parent directory ('%s') does not exist ", wt->parent_path); return GIT_ERROR; } if (!git_path_exists(wt->commondir_path)) { - giterr_set(GITERR_WORKTREE, + git_error_set(GIT_ERROR_WORKTREE, "Worktree common directory ('%s') does not exist ", wt->commondir_path); return GIT_ERROR; @@ -280,7 +280,7 @@ int git_worktree_add(git_worktree **out, git_repository *repo, git_worktree_add_options wtopts = GIT_WORKTREE_ADD_OPTIONS_INIT; int err; - GITERR_CHECK_VERSION( + GIT_ERROR_CHECK_VERSION( opts, GIT_WORKTREE_ADD_OPTIONS_VERSION, "git_worktree_add_options"); if (opts) @@ -343,13 +343,13 @@ int git_worktree_add(git_worktree **out, git_repository *repo, /* Set up worktree reference */ if (wtopts.ref) { if (!git_reference_is_branch(wtopts.ref)) { - giterr_set(GITERR_WORKTREE, "reference is not a branch"); + git_error_set(GIT_ERROR_WORKTREE, "reference is not a branch"); err = -1; goto out; } if (git_branch_is_checked_out(wtopts.ref)) { - giterr_set(GITERR_WORKTREE, "reference is already checked out"); + git_error_set(GIT_ERROR_WORKTREE, "reference is already checked out"); err = -1; goto out; } @@ -491,7 +491,7 @@ int git_worktree_is_prunable(git_worktree *wt, git_buf reason = GIT_BUF_INIT; git_worktree_prune_options popts = GIT_WORKTREE_PRUNE_OPTIONS_INIT; - GITERR_CHECK_VERSION( + GIT_ERROR_CHECK_VERSION( opts, GIT_WORKTREE_PRUNE_OPTIONS_VERSION, "git_worktree_prune_options"); @@ -503,7 +503,7 @@ int git_worktree_is_prunable(git_worktree *wt, { if (!reason.size) git_buf_attach_notowned(&reason, "no reason given", 15); - giterr_set(GITERR_WORKTREE, "Not pruning locked working tree: '%s'", reason.ptr); + git_error_set(GIT_ERROR_WORKTREE, "Not pruning locked working tree: '%s'", reason.ptr); git_buf_dispose(&reason); return 0; @@ -512,7 +512,7 @@ int git_worktree_is_prunable(git_worktree *wt, if ((popts.flags & GIT_WORKTREE_PRUNE_VALID) == 0 && git_worktree_validate(wt) == 0) { - giterr_set(GITERR_WORKTREE, "Not pruning valid working tree"); + git_error_set(GIT_ERROR_WORKTREE, "Not pruning valid working tree"); return 0; } @@ -527,7 +527,7 @@ int git_worktree_prune(git_worktree *wt, char *wtpath; int err; - GITERR_CHECK_VERSION( + GIT_ERROR_CHECK_VERSION( opts, GIT_WORKTREE_PRUNE_OPTIONS_VERSION, "git_worktree_prune_options"); @@ -544,7 +544,7 @@ int git_worktree_prune(git_worktree *wt, goto out; if (!git_path_exists(path.ptr)) { - giterr_set(GITERR_WORKTREE, "Worktree gitdir '%s' does not exist", path.ptr); + git_error_set(GIT_ERROR_WORKTREE, "Worktree gitdir '%s' does not exist", path.ptr); err = -1; goto out; } @@ -564,7 +564,7 @@ int git_worktree_prune(git_worktree *wt, git_buf_attach(&path, wtpath, 0); if (!git_path_exists(path.ptr)) { - giterr_set(GITERR_WORKTREE, "Working tree '%s' does not exist", path.ptr); + git_error_set(GIT_ERROR_WORKTREE, "Working tree '%s' does not exist", path.ptr); err = -1; goto out; } diff --git a/src/xdiff/xdiffi.c b/src/xdiff/xdiffi.c index 97db05466..9a7f53808 100644 --- a/src/xdiff/xdiffi.c +++ b/src/xdiff/xdiffi.c @@ -350,10 +350,10 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, * Allocate and setup K vectors to be used by the differential algorithm. * One is to store the forward path and one to store the backward path. */ - GITERR_CHECK_ALLOC_ADD3(&ndiags, xe->xdf1.nreff, xe->xdf2.nreff, 3); - GITERR_CHECK_ALLOC_MULTIPLY(&allocsize, ndiags, 2); - GITERR_CHECK_ALLOC_ADD(&allocsize, allocsize, 2); - GITERR_CHECK_ALLOC_MULTIPLY(&allocsize, allocsize, sizeof(long)); + GIT_ERROR_CHECK_ALLOC_ADD3(&ndiags, xe->xdf1.nreff, xe->xdf2.nreff, 3); + GIT_ERROR_CHECK_ALLOC_MULTIPLY(&allocsize, ndiags, 2); + GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, allocsize, 2); + GIT_ERROR_CHECK_ALLOC_MULTIPLY(&allocsize, allocsize, sizeof(long)); if (!(kvd = (long *) xdl_malloc(allocsize))) { xdl_free_env(xe); diff --git a/src/xdiff/xhistogram.c b/src/xdiff/xhistogram.c index ca8605e31..00bbfcec4 100644 --- a/src/xdiff/xhistogram.c +++ b/src/xdiff/xhistogram.c @@ -302,7 +302,7 @@ static int histogram_diff( index.table_bits = xdl_hashbits(count1); sz = index.records_size = 1 << index.table_bits; - GITERR_CHECK_ALLOC_MULTIPLY(&sz, sz, sizeof(struct record *)); + GIT_ERROR_CHECK_ALLOC_MULTIPLY(&sz, sz, sizeof(struct record *)); if (!(index.records = (struct record **) xdl_malloc(sz))) goto cleanup; diff --git a/src/xdiff/xmerge.c b/src/xdiff/xmerge.c index 6fec95aa3..e6eaf24b5 100644 --- a/src/xdiff/xmerge.c +++ b/src/xdiff/xmerge.c @@ -125,7 +125,7 @@ static int xdl_recs_copy_0(size_t *out, int use_orig, xdfenv_t *xe, int i, int c if (dest) memcpy(dest + size, recs[i]->ptr, recs[i]->size); - GITERR_CHECK_ALLOC_ADD(&size, size, recs[i++]->size); + GIT_ERROR_CHECK_ALLOC_ADD(&size, size, recs[i++]->size); } if (add_nl) { @@ -134,13 +134,13 @@ static int xdl_recs_copy_0(size_t *out, int use_orig, xdfenv_t *xe, int i, int c if (needs_cr) { if (dest) dest[size] = '\r'; - GITERR_CHECK_ALLOC_ADD(&size, size, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&size, size, 1); } if (dest) dest[size] = '\n'; - GITERR_CHECK_ALLOC_ADD(&size, size, 1); + GIT_ERROR_CHECK_ALLOC_ADD(&size, size, 1); } } @@ -224,10 +224,10 @@ static int fill_conflict_hunk(size_t *out, xdfenv_t *xe1, const char *name1, dest ? dest + size : NULL) < 0) return -1; - GITERR_CHECK_ALLOC_ADD(&size, size, copied); + GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied); if (!dest) { - GITERR_CHECK_ALLOC_ADD5(&size, size, marker_size, 1, needs_cr, marker1_size); + GIT_ERROR_CHECK_ALLOC_ADD5(&size, size, marker_size, 1, needs_cr, marker1_size); } else { memset(dest + size, '<', marker_size); size += marker_size; @@ -246,12 +246,12 @@ static int fill_conflict_hunk(size_t *out, xdfenv_t *xe1, const char *name1, dest ? dest + size : NULL) < 0) return -1; - GITERR_CHECK_ALLOC_ADD(&size, size, copied); + GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied); if (style == XDL_MERGE_DIFF3) { /* Shared preimage */ if (!dest) { - GITERR_CHECK_ALLOC_ADD5(&size, size, marker_size, 1, needs_cr, marker3_size); + GIT_ERROR_CHECK_ALLOC_ADD5(&size, size, marker_size, 1, needs_cr, marker3_size); } else { memset(dest + size, '|', marker_size); size += marker_size; @@ -268,11 +268,11 @@ static int fill_conflict_hunk(size_t *out, xdfenv_t *xe1, const char *name1, if (xdl_orig_copy(&copied, xe1, m->i0, m->chg0, needs_cr, 1, dest ? dest + size : NULL) < 0) return -1; - GITERR_CHECK_ALLOC_ADD(&size, size, copied); + GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied); } if (!dest) { - GITERR_CHECK_ALLOC_ADD4(&size, size, marker_size, 1, needs_cr); + GIT_ERROR_CHECK_ALLOC_ADD4(&size, size, marker_size, 1, needs_cr); } else { memset(dest + size, '=', marker_size); size += marker_size; @@ -286,10 +286,10 @@ static int fill_conflict_hunk(size_t *out, xdfenv_t *xe1, const char *name1, if (xdl_recs_copy(&copied, xe2, m->i2, m->chg2, needs_cr, 1, dest ? dest + size : NULL) < 0) return -1; - GITERR_CHECK_ALLOC_ADD(&size, size, copied); + GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied); if (!dest) { - GITERR_CHECK_ALLOC_ADD5(&size, size, marker_size, 1, needs_cr, marker2_size); + GIT_ERROR_CHECK_ALLOC_ADD5(&size, size, marker_size, 1, needs_cr, marker2_size); } else { memset(dest + size, '>', marker_size); size += marker_size; @@ -336,7 +336,7 @@ static int xdl_fill_merge_buffer(size_t *out, if (xdl_recs_copy(&copied, xe1, i, m->i1 - i, 0, 0, dest ? dest + size : NULL) < 0) return -1; - GITERR_CHECK_ALLOC_ADD(&size, size, copied); + GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied); /* Postimage from side #1 */ if (m->mode & 1) { @@ -345,7 +345,7 @@ static int xdl_fill_merge_buffer(size_t *out, if (xdl_recs_copy(&copied, xe1, m->i1, m->chg1, needs_cr, (m->mode & 2), dest ? dest + size : NULL) < 0) return -1; - GITERR_CHECK_ALLOC_ADD(&size, size, copied); + GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied); } /* Postimage from side #2 */ @@ -353,7 +353,7 @@ static int xdl_fill_merge_buffer(size_t *out, if (xdl_recs_copy(&copied, xe2, m->i2, m->chg2, 0, 0, dest ? dest + size : NULL) < 0) return -1; - GITERR_CHECK_ALLOC_ADD(&size, size, copied); + GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied); } } else continue; @@ -363,7 +363,7 @@ static int xdl_fill_merge_buffer(size_t *out, if (xdl_recs_copy(&copied, xe1, i, xe1->xdf2.nrec - i, 0, 0, dest ? dest + size : NULL) < 0) return -1; - GITERR_CHECK_ALLOC_ADD(&size, size, copied); + GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied); *out = size; return 0; diff --git a/src/zstream.c b/src/zstream.c index affa55653..fc8bfb868 100644 --- a/src/zstream.c +++ b/src/zstream.c @@ -22,13 +22,13 @@ GIT_INLINE(int) zstream_seterr(git_zstream *zs) case Z_BUF_ERROR: /* not fatal; we retry with a larger buffer */ return 0; case Z_MEM_ERROR: - giterr_set_oom(); + git_error_set_oom(); break; default: if (zs->z.msg) - giterr_set_str(GITERR_ZLIB, zs->z.msg); + git_error_set_str(GIT_ERROR_ZLIB, zs->z.msg); else - giterr_set(GITERR_ZLIB, "unknown compression error"); + git_error_set(GIT_ERROR_ZLIB, "unknown compression error"); } return -1; @@ -136,7 +136,7 @@ int git_zstream_get_output(void *out, size_t *out_len, git_zstream *zstream) size_t out_remain = *out_len; if (zstream->in_len && zstream->zerr == Z_STREAM_END) { - giterr_set(GITERR_ZLIB, "zlib input had trailing garbage"); + git_error_set(GIT_ERROR_ZLIB, "zlib input had trailing garbage"); return -1; } |