Skip to content

Return int from non-free functions #5365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/git2/attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,11 @@ GIT_EXTERN(int) git_attr_foreach(
* disk no longer match the cached contents of memory. This will cause
* the attributes files to be reloaded the next time that an attribute
* access function is called.
*
* @param repo The repository containing the gitattributes cache
* @return 0 on success, or an error code
*/
GIT_EXTERN(void) git_attr_cache_flush(
GIT_EXTERN(int) git_attr_cache_flush(
git_repository *repo);

/**
Expand Down
3 changes: 2 additions & 1 deletion include/git2/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ GIT_BEGIN_DECL
* @param major Store the major version number
* @param minor Store the minor version number
* @param rev Store the revision (patch) number
* @return 0 on success or an error code on failure
*/
GIT_EXTERN(void) git_libgit2_version(int *major, int *minor, int *rev);
GIT_EXTERN(int) git_libgit2_version(int *major, int *minor, int *rev);

/**
* Combinations of these values describe the features with which libgit2
Expand Down
3 changes: 2 additions & 1 deletion include/git2/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ GIT_EXTERN(void) git_error_clear(void);
* @param error_class One of the `git_error_t` enum above describing the
* general subsystem that is responsible for the error.
* @param string The formatted error message to keep
* @return 0 on success or -1 on failure
*/
GIT_EXTERN(void) git_error_set_str(int error_class, const char *string);
GIT_EXTERN(int) git_error_set_str(int error_class, const char *string);

/**
* Set the error message to a special value for memory allocation failure.
Expand Down
15 changes: 10 additions & 5 deletions include/git2/oid.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length);
*
* @param out oid structure the result is written into.
* @param raw the raw input bytes to be copied.
* @return 0 on success or error code
*/
GIT_EXTERN(void) git_oid_fromraw(git_oid *out, const unsigned char *raw);
GIT_EXTERN(int) git_oid_fromraw(git_oid *out, const unsigned char *raw);

/**
* Format a git_oid into a hex string.
Expand All @@ -85,8 +86,9 @@ GIT_EXTERN(void) git_oid_fromraw(git_oid *out, const unsigned char *raw);
* oid digits are written; a '\\0' terminator must be added
* by the caller if it is required.
* @param id oid structure to format.
* @return 0 on success or error code
*/
GIT_EXTERN(void) git_oid_fmt(char *out, const git_oid *id);
GIT_EXTERN(int) git_oid_fmt(char *out, const git_oid *id);

/**
* Format a git_oid into a partial hex string.
Expand All @@ -96,8 +98,9 @@ GIT_EXTERN(void) git_oid_fmt(char *out, const git_oid *id);
* will be zeroed; if not, a '\0' terminator is NOT added.
* @param n number of characters to write into out string
* @param id oid structure to format.
* @return 0 on success or error code
*/
GIT_EXTERN(void) git_oid_nfmt(char *out, size_t n, const git_oid *id);
GIT_EXTERN(int) git_oid_nfmt(char *out, size_t n, const git_oid *id);

/**
* Format a git_oid into a loose-object path string.
Expand All @@ -111,8 +114,9 @@ GIT_EXTERN(void) git_oid_nfmt(char *out, size_t n, const git_oid *id);
* oid digits are written; a '\\0' terminator must be added
* by the caller if it is required.
* @param id oid structure to format.
* @return 0 on success, non-zero callback return value, or error code
*/
GIT_EXTERN(void) git_oid_pathfmt(char *out, const git_oid *id);
GIT_EXTERN(int) git_oid_pathfmt(char *out, const git_oid *id);

/**
* Format a git_oid into a statically allocated c-string.
Expand Down Expand Up @@ -151,8 +155,9 @@ GIT_EXTERN(char *) git_oid_tostr(char *out, size_t n, const git_oid *id);
*
* @param out oid structure the result is written into.
* @param src oid structure to copy from.
* @return 0 on success or error code
*/
GIT_EXTERN(void) git_oid_cpy(git_oid *out, const git_oid *src);
GIT_EXTERN(int) git_oid_cpy(git_oid *out, const git_oid *src);

/**
* Compare two oid structures.
Expand Down
6 changes: 4 additions & 2 deletions include/git2/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,17 +378,19 @@ GIT_EXTERN(int) git_remote_connected(const git_remote *remote);
* the operation has been cancelled and if so stops the operation.
*
* @param remote the remote
* @return 0 on success, or an error code
*/
GIT_EXTERN(void) git_remote_stop(git_remote *remote);
GIT_EXTERN(int) git_remote_stop(git_remote *remote);

/**
* Disconnect from the remote
*
* Close the connection to the remote.
*
* @param remote the remote to disconnect from
* @return 0 on success, or an error code
*/
GIT_EXTERN(void) git_remote_disconnect(git_remote *remote);
GIT_EXTERN(int) git_remote_disconnect(git_remote *remote);

/**
* Free the memory associated with a remote
Expand Down
10 changes: 7 additions & 3 deletions include/git2/revwalk.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ GIT_EXTERN(int) git_revwalk_new(git_revwalk **out, git_repository *repo);
* is over.
*
* @param walker handle to reset.
* @return 0 or an error code
*/
GIT_EXTERN(void) git_revwalk_reset(git_revwalk *walker);
GIT_EXTERN(int) git_revwalk_reset(git_revwalk *walker);

/**
* Add a new root for the traversal
Expand Down Expand Up @@ -224,8 +225,9 @@ GIT_EXTERN(int) git_revwalk_next(git_oid *out, git_revwalk *walk);
*
* @param walk the walker being used for the traversal.
* @param sort_mode combination of GIT_SORT_XXX flags
* @return 0 or an error code
*/
GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode);
GIT_EXTERN(int) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode);

/**
* Push and hide the respective endpoints of the given range.
Expand All @@ -246,8 +248,10 @@ GIT_EXTERN(int) git_revwalk_push_range(git_revwalk *walk, const char *range);
* Simplify the history by first-parent
*
* No parents other than the first for each commit will be enqueued.
*
* @return 0 or an error code
*/
GIT_EXTERN(void) git_revwalk_simplify_first_parent(git_revwalk *walk);
GIT_EXTERN(int) git_revwalk_simplify_first_parent(git_revwalk *walk);


/**
Expand Down
6 changes: 4 additions & 2 deletions include/git2/sys/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ GIT_EXTERN(int) git_index_name_add(git_index *index,
* Remove all filename conflict entries.
*
* @param index an existing index object
* @return 0 or an error code
*/
GIT_EXTERN(void) git_index_name_clear(git_index *index);
GIT_EXTERN(int) git_index_name_clear(git_index *index);

/**@}*/

Expand Down Expand Up @@ -170,8 +171,9 @@ GIT_EXTERN(int) git_index_reuc_remove(git_index *index, size_t n);
* Remove all resolve undo entries from the index
*
* @param index an existing index object
* @return 0 or an error code
*/
GIT_EXTERN(void) git_index_reuc_clear(git_index *index);
GIT_EXTERN(int) git_index_reuc_clear(git_index *index);

/**@}*/

Expand Down
3 changes: 2 additions & 1 deletion include/git2/sys/mempack.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ GIT_EXTERN(int) git_mempack_dump(git_buf *pack, git_repository *repo, git_odb_ba
* semantics to the Git repository.
*
* @param backend The mempack backend
* @return 0 on success; error code otherwise
*/
GIT_EXTERN(void) git_mempack_reset(git_odb_backend *backend);
GIT_EXTERN(int) git_mempack_reset(git_odb_backend *backend);

GIT_END_DECL

Expand Down
17 changes: 12 additions & 5 deletions include/git2/sys/repository.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ GIT_EXTERN(int) git_repository_new(git_repository **out);
* trying to aggressively cleanup the repo before its
* deallocation. `git_repository_free` already performs this operation
* before deallocating the repo.
*
* @param repo The repository to clean up
* @return 0 on success, or an error code
*/
GIT_EXTERN(void) git_repository__cleanup(git_repository *repo);
GIT_EXTERN(int) git_repository__cleanup(git_repository *repo);

/**
* Update the filesystem config settings for an open repository
Expand Down Expand Up @@ -78,8 +81,9 @@ GIT_EXTERN(int) git_repository_reinit_filesystem(
*
* @param repo A repository object
* @param config A Config object
* @return 0 on success, or an error code
*/
GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *config);
GIT_EXTERN(int) git_repository_set_config(git_repository *repo, git_config *config);

/**
* Set the Object Database for this repository
Expand All @@ -93,8 +97,9 @@ GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *con
*
* @param repo A repository object
* @param odb An ODB object
* @return 0 on success, or an error code
*/
GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb);
GIT_EXTERN(int) git_repository_set_odb(git_repository *repo, git_odb *odb);

/**
* Set the Reference Database Backend for this repository
Expand All @@ -108,8 +113,9 @@ GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb);
*
* @param repo A repository object
* @param refdb An refdb object
* @return 0 on success, or an error code
*/
GIT_EXTERN(void) git_repository_set_refdb(git_repository *repo, git_refdb *refdb);
GIT_EXTERN(int) git_repository_set_refdb(git_repository *repo, git_refdb *refdb);

/**
* Set the index file for this repository
Expand All @@ -123,8 +129,9 @@ GIT_EXTERN(void) git_repository_set_refdb(git_repository *repo, git_refdb *refdb
*
* @param repo A repository object
* @param index An index object
* @return 0 on success, or an error code
*/
GIT_EXTERN(void) git_repository_set_index(git_repository *repo, git_index *index);
GIT_EXTERN(int) git_repository_set_index(git_repository *repo, git_index *index);

/**
* Set a repository to be bare.
Expand Down
6 changes: 4 additions & 2 deletions include/git2/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,9 @@ GIT_EXTERN(int) git_treebuilder_new(
* Clear all the entires in the builder
*
* @param bld Builder to clear
* @return 0 on success; error code otherwise
*/
GIT_EXTERN(void) git_treebuilder_clear(git_treebuilder *bld);
GIT_EXTERN(int) git_treebuilder_clear(git_treebuilder *bld);

/**
* Get the number of entries listed in a treebuilder
Expand Down Expand Up @@ -357,8 +358,9 @@ typedef int GIT_CALLBACK(git_treebuilder_filter_cb)(
* @param bld Tree builder
* @param filter Callback to filter entries
* @param payload Extra data to pass to filter callback
* @return 0 on success, non-zero callback return value, or error code
*/
GIT_EXTERN(void) git_treebuilder_filter(
GIT_EXTERN(int) git_treebuilder_filter(
git_treebuilder *bld,
git_treebuilder_filter_cb filter,
void *payload);
Expand Down
4 changes: 3 additions & 1 deletion src/attrcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ int git_attr_cache__init(git_repository *repo)
return ret;
}

void git_attr_cache_flush(git_repository *repo)
int git_attr_cache_flush(git_repository *repo)
{
git_attr_cache *cache;

Expand All @@ -420,6 +420,8 @@ void git_attr_cache_flush(git_repository *repo)
*/
if (repo && (cache = git__swap(repo->attrcache, NULL)) != NULL)
attr_cache__free(cache);

return 0;
}

int git_attr_cache__insert_macro(git_repository *repo, git_attr_rule *macro)
Expand Down
16 changes: 11 additions & 5 deletions src/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,25 @@ void git_error_vset(int error_class, const char *fmt, va_list ap)
set_error_from_buffer(error_class);
}

void git_error_set_str(int error_class, const char *string)
int git_error_set_str(int error_class, const char *string)
{
git_buf *buf = &GIT_GLOBAL->error_buf;

assert(string);

if (!string)
return;
if (!string) {
git_error_set(GIT_ERROR_INVALID, "unspecified caller error");
return -1;
}

git_buf_clear(buf);
git_buf_puts(buf, string);
if (!git_buf_oom(buf))
set_error_from_buffer(error_class);

if (git_buf_oom(buf))
return -1;

set_error_from_buffer(error_class);
return 0;
}

void git_error_clear(void)
Expand Down
23 changes: 17 additions & 6 deletions src/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,19 @@ int git_index_clear(git_index *index)
git_idxmap_clear(index->entries_map);
while (!error && index->entries.length > 0)
error = index_remove_entry(index, index->entries.length - 1);

if (error)
goto done;

index_free_deleted(index);

git_index_reuc_clear(index);
git_index_name_clear(index);
if ((error = git_index_name_clear(index)) < 0 ||
(error = git_index_reuc_clear(index)) < 0)
goto done;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: indentation


git_futils_filestamp_set(&index->stamp, NULL);

done:
return error;
}

Expand Down Expand Up @@ -2136,7 +2142,7 @@ int git_index_name_add(git_index *index,
return 0;
}

void git_index_name_clear(git_index *index)
int git_index_name_clear(git_index *index)
{
size_t i;
git_index_name_entry *conflict_name;
Expand All @@ -2149,6 +2155,8 @@ void git_index_name_clear(git_index *index)
git_vector_clear(&index->names);

index->dirty = 1;

return 0;
}

size_t git_index_reuc_entrycount(git_index *index)
Expand Down Expand Up @@ -2245,7 +2253,7 @@ int git_index_reuc_remove(git_index *index, size_t position)
return error;
}

void git_index_reuc_clear(git_index *index)
int git_index_reuc_clear(git_index *index)
{
size_t i;

Expand All @@ -2257,6 +2265,8 @@ void git_index_reuc_clear(git_index *index)
git_vector_clear(&index->reuc);

index->dirty = 1;

return 0;
}

static int index_error_invalid(const char *message)
Expand Down Expand Up @@ -3277,8 +3287,9 @@ static int git_index_read_iterator(
}
}

git_index_name_clear(index);
git_index_reuc_clear(index);
if ((error = git_index_name_clear(index)) < 0 ||
(error = git_index_reuc_clear(index)) < 0)
goto done;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well


git_vector_swap(&new_entries, &index->entries);
new_entries_map = git__swap(index->entries_map, new_entries_map);
Expand Down
4 changes: 3 additions & 1 deletion src/odb_mempack.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int git_mempack_dump(git_buf *pack, git_repository *repo, git_odb_backend *_back
return err;
}

void git_mempack_reset(git_odb_backend *_backend)
int git_mempack_reset(git_odb_backend *_backend)
{
struct memory_packer_db *db = (struct memory_packer_db *)_backend;
struct memobject *object = NULL;
Expand All @@ -137,6 +137,8 @@ void git_mempack_reset(git_odb_backend *_backend)
git_array_clear(db->commits);

git_oidmap_clear(db->objects);

return 0;
}

static void impl__free(git_odb_backend *_backend)
Expand Down
Loading