Skip to content

Commit

Permalink
errors: Rename error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
vmg committed May 17, 2012
1 parent e172cf0 commit 904b67e
Show file tree
Hide file tree
Showing 61 changed files with 171 additions and 170 deletions.
4 changes: 2 additions & 2 deletions examples/diff.c
Expand Up @@ -36,7 +36,7 @@ int resolve_to_tree(git_repository *repo, const char *identifier, git_tree **tre
}

if (obj == NULL)
return GIT_NOTFOUND;
return GIT_ENOTFOUND;

switch (git_object_type(obj)) {
case GIT_OBJ_TREE:
Expand All @@ -47,7 +47,7 @@ int resolve_to_tree(git_repository *repo, const char *identifier, git_tree **tre
git_object_free(obj);
break;
default:
err = GIT_NOTFOUND;
err = GIT_ENOTFOUND;
}

return err;
Expand Down
4 changes: 2 additions & 2 deletions include/git2/branch.h
Expand Up @@ -63,7 +63,7 @@ GIT_EXTERN(int) git_branch_create(
* @param branch_type Type of the considered branch. This should
* be valued with either GIT_BRANCH_LOCAL or GIT_BRANCH_REMOTE.
*
* @return 0 on success, GIT_NOTFOUND if the branch
* @return 0 on success, GIT_ENOTFOUND if the branch
* doesn't exist or an error code.
*/
GIT_EXTERN(int) git_branch_delete(
Expand Down Expand Up @@ -108,7 +108,7 @@ GIT_EXTERN(int) git_branch_list(
*
* @param force Overwrite existing branch.
*
* @return 0 on success, GIT_NOTFOUND if the branch
* @return 0 on success, GIT_ENOTFOUND if the branch
* doesn't exist or an error code.
*/
GIT_EXTERN(int) git_branch_move(
Expand Down
11 changes: 6 additions & 5 deletions include/git2/errors.h
Expand Up @@ -58,12 +58,13 @@ enum {
enum {
GIT_OK = 0,
GIT_ERROR = -1,
GIT_NOTFOUND = -3,
GIT_EXISTS = -23,
GIT_AMBIGUOUS = -29,
GIT_ENOTFOUND = -3,
GIT_EEXISTS = -4,
GIT_EAMBIGUOUS = -5,
GIT_EBUFS = -6,

GIT_PASSTHROUGH = -30,
GIT_SHORTBUFFER = -32,
GIT_REVWALKOVER = -33,
GIT_REVWALKOVER = -31,
};

typedef struct {
Expand Down
8 changes: 4 additions & 4 deletions include/git2/odb.h
Expand Up @@ -109,7 +109,7 @@ GIT_EXTERN(void) git_odb_free(git_odb *db);
* @param id identity of the object to read.
* @return
* - 0 if the object was read;
* - GIT_NOTFOUND if the object is not in the database.
* - GIT_ENOTFOUND if the object is not in the database.
*/
GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id);

Expand All @@ -136,8 +136,8 @@ GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *i
* @param short_id a prefix of the id of the object to read.
* @param len the length of the prefix
* @return 0 if the object was read;
* GIT_NOTFOUND if the object is not in the database.
* GIT_AMBIGUOUS if the prefix is ambiguous (several objects match the prefix)
* GIT_ENOTFOUND if the object is not in the database.
* GIT_EAMBIGUOUS if the prefix is ambiguous (several objects match the prefix)
*/
GIT_EXTERN(int) git_odb_read_prefix(git_odb_object **out, git_odb *db, const git_oid *short_id, unsigned int len);

Expand All @@ -157,7 +157,7 @@ GIT_EXTERN(int) git_odb_read_prefix(git_odb_object **out, git_odb *db, const git
* @param id identity of the object to read.
* @return
* - 0 if the object was read;
* - GIT_NOTFOUND if the object is not in the database.
* - GIT_ENOTFOUND if the object is not in the database.
*/
GIT_EXTERN(int) git_odb_read_header(size_t *len_p, git_otype *type_p, git_odb *db, const git_oid *id);

Expand Down
2 changes: 1 addition & 1 deletion include/git2/refspec.h
Expand Up @@ -51,7 +51,7 @@ GIT_EXTERN(int) git_refspec_src_matches(const git_refspec *refspec, const char *
* @param outlen the size ouf the `out` buffer
* @param spec the refspec
* @param name the name of the reference to transform
* @return 0, GIT_SHORTBUFFER or another error
* @return 0, GIT_EBUFS or another error
*/
GIT_EXTERN(int) git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name);

Expand Down
2 changes: 1 addition & 1 deletion include/git2/status.h
Expand Up @@ -131,7 +131,7 @@ GIT_EXTERN(int) git_status_foreach_ext(
* @param status_flags the status value
* @param repo a repository object
* @param path the file to retrieve status for, rooted at the repo's workdir
* @return GIT_EINVALIDPATH when `path` points at a folder, GIT_NOTFOUND when
* @return GIT_EINVALIDPATH when `path` points at a folder, GIT_ENOTFOUND when
* the file doesn't exist in any of HEAD, the index or the worktree,
* 0 otherwise
*/
Expand Down
4 changes: 2 additions & 2 deletions include/git2/submodule.h
Expand Up @@ -85,13 +85,13 @@ GIT_EXTERN(int) git_submodule_foreach(
*
* Given either the submodule name or path (they are ususally the same),
* this returns a structure describing the submodule. If the submodule
* does not exist, this will return GIT_NOTFOUND and set the submodule
* does not exist, this will return GIT_ENOTFOUND and set the submodule
* pointer to NULL.
*
* @param submodule Pointer to submodule description object pointer..
* @param repo The repository.
* @param name The name of the submodule. Trailing slashes will be ignored.
* @return 0 on success, GIT_NOTFOUND if submodule does not exist, -1 on error
* @return 0 on success, GIT_ENOTFOUND if submodule does not exist, -1 on error
*/
GIT_EXTERN(int) git_submodule_lookup(
git_submodule **submodule,
Expand Down
4 changes: 2 additions & 2 deletions include/git2/tag.h
Expand Up @@ -143,7 +143,7 @@ GIT_EXTERN(const char *) git_tag_message(git_tag *tag);
* @param oid Pointer where to store the OID of the
* newly created tag. If the tag already exists, this parameter
* will be the oid of the existing tag, and the function will
* return a GIT_EXISTS error code.
* return a GIT_EEXISTS error code.
*
* @param repo Repository where to store the tag
*
Expand Down Expand Up @@ -199,7 +199,7 @@ GIT_EXTERN(int) git_tag_create_frombuffer(
* @param oid Pointer where to store the OID of the provided
* target object. If the tag already exists, this parameter
* will be filled with the oid of the existing pointed object
* and the function will return a GIT_EXISTS error code.
* and the function will return a GIT_EEXISTS error code.
*
* @param repo Repository where to store the lightweight tag
*
Expand Down
2 changes: 1 addition & 1 deletion include/git2/tree.h
Expand Up @@ -278,7 +278,7 @@ GIT_EXTERN(int) git_treebuilder_write(git_oid *oid, git_repository *repo, git_tr
* @param subtree Pointer where to store the subtree
* @param root A previously loaded tree which will be the root of the relative path
* @param subtree_path Path to the contained subtree
* @return 0 on success; GIT_NOTFOUND if the path does not lead to a subtree
* @return 0 on success; GIT_ENOTFOUND if the path does not lead to a subtree
*/
GIT_EXTERN(int) git_tree_get_subtree(git_tree **subtree, git_tree *root, const char *subtree_path);

Expand Down
14 changes: 7 additions & 7 deletions src/attr.c
Expand Up @@ -245,13 +245,13 @@ static int load_attr_file(
struct stat st;

if (p_stat(filename, &st) < 0)
return GIT_NOTFOUND;
return GIT_ENOTFOUND;

if (sig != NULL &&
(git_time_t)st.st_mtime == sig->seconds &&
(git_off_t)st.st_size == sig->size &&
(unsigned int)st.st_ino == sig->ino)
return GIT_NOTFOUND;
return GIT_ENOTFOUND;

error = git_futils_readbuffer_updated(&content, filename, NULL, NULL);
if (error < 0)
Expand Down Expand Up @@ -286,7 +286,7 @@ static int load_attr_blob_from_index(
entry = git_index_get(index, error);

if (old_oid && git_oid_cmp(old_oid, &entry->oid) == 0)
return GIT_NOTFOUND;
return GIT_ENOTFOUND;

if ((error = git_blob_lookup(blob, repo, &entry->oid)) < 0)
return error;
Expand Down Expand Up @@ -396,7 +396,7 @@ int git_attr_cache__push_file(

if (error) {
/* not finding a file is not an error for this function */
if (error == GIT_NOTFOUND) {
if (error == GIT_ENOTFOUND) {
giterr_clear();
error = 0;
}
Expand Down Expand Up @@ -550,7 +550,7 @@ static int collect_attr_files(
error = git_futils_find_system_file(&dir, GIT_ATTR_FILE_SYSTEM);
if (!error)
error = push_attr_file(repo, files, NULL, dir.ptr);
else if (error == GIT_NOTFOUND)
else if (error == GIT_ENOTFOUND)
error = 0;
}

Expand All @@ -577,11 +577,11 @@ int git_attr_cache__init(git_repository *repo)
return -1;

ret = git_config_get_string(&cache->cfg_attr_file, cfg, GIT_ATTR_CONFIG);
if (ret < 0 && ret != GIT_NOTFOUND)
if (ret < 0 && ret != GIT_ENOTFOUND)
return ret;

ret = git_config_get_string(&cache->cfg_excl_file, cfg, GIT_IGNORE_CONFIG);
if (ret < 0 && ret != GIT_NOTFOUND)
if (ret < 0 && ret != GIT_ENOTFOUND)
return ret;

giterr_clear();
Expand Down
14 changes: 7 additions & 7 deletions src/attr_file.c
Expand Up @@ -99,7 +99,7 @@ int git_attr_file__parse_buffer(
/* if the rule wasn't a pattern, on to the next */
if (error < 0) {
git_attr_rule__clear(rule); /* reset rule contents */
if (error == GIT_NOTFOUND)
if (error == GIT_ENOTFOUND)
error = 0;
} else {
rule = NULL; /* vector now "owns" the rule */
Expand Down Expand Up @@ -328,7 +328,7 @@ void git_attr_path__free(git_attr_path *info)

/*
* This will return 0 if the spec was filled out,
* GIT_NOTFOUND if the fnmatch does not require matching, or
* GIT_ENOTFOUND if the fnmatch does not require matching, or
* another error code there was an actual problem.
*/
int git_attr_fnmatch__parse(
Expand All @@ -347,7 +347,7 @@ int git_attr_fnmatch__parse(
while (git__isspace(*pattern)) pattern++;
if (!*pattern || *pattern == '#') {
*base = git__next_line(pattern);
return GIT_NOTFOUND;
return GIT_ENOTFOUND;
}

spec->flags = 0;
Expand Down Expand Up @@ -464,7 +464,7 @@ static int merge_assignments(void **old_raw, void *new_raw)

GIT_REFCOUNT_DEC(*old, git_attr_assignment__free);
*old = new;
return GIT_EXISTS;
return GIT_EEXISTS;
}

int git_attr_assignment__parse(
Expand Down Expand Up @@ -551,15 +551,15 @@ int git_attr_assignment__parse(

error = git_vector_insert_sorted(
assigns, massign, &merge_assignments);
if (error < 0 && error != GIT_EXISTS)
if (error < 0 && error != GIT_EEXISTS)
return error;
}
}
}

/* insert allocated assign into vector */
error = git_vector_insert_sorted(assigns, assign, &merge_assignments);
if (error < 0 && error != GIT_EXISTS)
if (error < 0 && error != GIT_EEXISTS)
return error;

/* clear assign since it is now "owned" by the vector */
Expand All @@ -571,7 +571,7 @@ int git_attr_assignment__parse(

*base = git__next_line(scan);

return (assigns->length == 0) ? GIT_NOTFOUND : 0;
return (assigns->length == 0) ? GIT_ENOTFOUND : 0;
}

static void git_attr_rule__clear(git_attr_rule *rule)
Expand Down
2 changes: 1 addition & 1 deletion src/branch.c
Expand Up @@ -190,7 +190,7 @@ int git_branch_move(git_repository *repo, const char *old_branch_name, const cha
if ((error = git_buf_joinpath(&old_reference_name, GIT_REFS_HEADS_DIR, old_branch_name)) < 0)
goto cleanup;

/* We need to be able to return GIT_NOTFOUND */
/* We need to be able to return GIT_ENOTFOUND */
if ((error = git_reference_lookup(&reference, repo, git_buf_cstr(&old_reference_name))) < 0)
goto cleanup;

Expand Down
6 changes: 3 additions & 3 deletions src/commit.c
Expand Up @@ -100,7 +100,7 @@ static int update_reference(git_repository *repo, git_oid *oid, const char *ref_

/* If we haven't found the reference at all, we assume we need to create
* a new reference and that's it */
if (res == GIT_NOTFOUND) {
if (res == GIT_ENOTFOUND) {
giterr_clear();
return git_reference_create_oid(NULL, repo, ref_name, oid, 1);
}
Expand All @@ -125,7 +125,7 @@ static int update_reference(git_repository *repo, git_oid *oid, const char *ref_
* this is means we're creating a new branch, for example.
* We need to create a new direct reference with that name
*/
if (res == GIT_NOTFOUND) {
if (res == GIT_ENOTFOUND) {
giterr_clear();
res = git_reference_create_oid(NULL, repo, sym_target, oid, 1);
git_reference_free(ref);
Expand Down Expand Up @@ -320,7 +320,7 @@ int git_commit_parent(git_commit **parent, git_commit *commit, unsigned int n)
parent_oid = git_vector_get(&commit->parent_oids, n);
if (parent_oid == NULL) {
giterr_set(GITERR_INVALID, "Parent %u does not exist", n);
return GIT_NOTFOUND;
return GIT_ENOTFOUND;
}

return git_commit_lookup(parent, commit->object.repo, parent_oid);
Expand Down
16 changes: 8 additions & 8 deletions src/config.c
Expand Up @@ -263,7 +263,7 @@ int git_config_lookup_map_value(
size_t i;

if (!value)
return GIT_NOTFOUND;
return GIT_ENOTFOUND;

for (i = 0; i < map_n; ++i) {
git_cvar_map *m = maps + i;
Expand Down Expand Up @@ -295,7 +295,7 @@ int git_config_lookup_map_value(
}
}

return GIT_NOTFOUND;
return GIT_ENOTFOUND;
}

int git_config_get_mapped(
Expand Down Expand Up @@ -387,20 +387,20 @@ int git_config_get_string(const char **out, git_config *cfg, const char *name)
git_vector_foreach(&cfg->files, i, internal) {
git_config_file *file = internal->file;
int ret = file->get(file, name, out);
if (ret != GIT_NOTFOUND)
if (ret != GIT_ENOTFOUND)
return ret;
}

giterr_set(GITERR_CONFIG, "Config variable '%s' not found", name);
return GIT_NOTFOUND;
return GIT_ENOTFOUND;
}

int git_config_get_multivar(git_config *cfg, const char *name, const char *regexp,
int (*fn)(const char *value, void *data), void *data)
{
file_internal *internal;
git_config_file *file;
int ret = GIT_NOTFOUND;
int ret = GIT_ENOTFOUND;
unsigned int i;

assert(cfg->files.length);
Expand All @@ -413,7 +413,7 @@ int git_config_get_multivar(git_config *cfg, const char *name, const char *regex
internal = git_vector_get(&cfg->files, i - 1);
file = internal->file;
ret = file->get_multivar(file, name, regexp, fn, data);
if (ret < 0 && ret != GIT_NOTFOUND)
if (ret < 0 && ret != GIT_ENOTFOUND)
return ret;
}

Expand All @@ -424,14 +424,14 @@ int git_config_set_multivar(git_config *cfg, const char *name, const char *regex
{
file_internal *internal;
git_config_file *file;
int ret = GIT_NOTFOUND;
int ret = GIT_ENOTFOUND;
unsigned int i;

for (i = cfg->files.length; i > 0; --i) {
internal = git_vector_get(&cfg->files, i - 1);
file = internal->file;
ret = file->set_multivar(file, name, regexp, value);
if (ret < 0 && ret != GIT_NOTFOUND)
if (ret < 0 && ret != GIT_ENOTFOUND)
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/config_cache.c
Expand Up @@ -72,7 +72,7 @@ int git_repository__cvar(int *out, git_repository *repo, git_cvar_cached cvar)
error = git_config_get_mapped(out,
config, data->cvar_name, data->maps, data->map_count);

if (error == GIT_NOTFOUND)
if (error == GIT_ENOTFOUND)
*out = data->default_value;

else if (error < 0)
Expand Down

0 comments on commit 904b67e

Please sign in to comment.