Skip to content

Commit

Permalink
git_error: use new names in internal APIs and usage
Browse files Browse the repository at this point in the history
Move to the `git_error` name in the internal API for error-related
functions.
  • Loading branch information
ethomson committed Jan 22, 2019
1 parent 647dfdb commit f673e23
Show file tree
Hide file tree
Showing 184 changed files with 1,944 additions and 1,944 deletions.
2 changes: 1 addition & 1 deletion src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions src/annotated_commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions src/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -155,7 +155,7 @@ static int update_hunk(
&image->lines, linenum, (prelen - postlen));

if (error) {
giterr_set_oom();
git_error_set_oom();
return -1;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
*
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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, "."))
Expand Down
18 changes: 9 additions & 9 deletions src/attr_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 == '=') {
Expand All @@ -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);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/attrcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions src/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit f673e23

Please sign in to comment.