mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-08 02:36:11 +00:00
Add git_vector_free_all
There are a lot of places that we call git__free on each item in a vector and then call git_vector_free on the vector itself. This just wraps that up into one convenient helper function.
This commit is contained in:
parent
dab89f9b68
commit
fcd324c625
@ -132,7 +132,6 @@ void git_blame_free(git_blame *blame)
|
||||
{
|
||||
size_t i;
|
||||
git_blame_hunk *hunk;
|
||||
char *path;
|
||||
|
||||
if (!blame) return;
|
||||
|
||||
@ -140,9 +139,7 @@ void git_blame_free(git_blame *blame)
|
||||
free_hunk(hunk);
|
||||
git_vector_free(&blame->hunks);
|
||||
|
||||
git_vector_foreach(&blame->paths, i, path)
|
||||
git__free(path);
|
||||
git_vector_free(&blame->paths);
|
||||
git_vector_free_all(&blame->paths);
|
||||
|
||||
git_array_clear(blame->line_index);
|
||||
|
||||
|
@ -846,7 +846,7 @@ static int checkout_conflicts_coalesce_renames(
|
||||
|
||||
/* Juggle entries based on renames */
|
||||
names = git_index_name_entrycount(data->index);
|
||||
|
||||
|
||||
for (i = 0; i < names; i++) {
|
||||
name_entry = git_index_name_get_byindex(data->index, i);
|
||||
|
||||
@ -1760,9 +1760,6 @@ static int checkout_create_conflicts(checkout_data *data)
|
||||
|
||||
static void checkout_data_clear(checkout_data *data)
|
||||
{
|
||||
checkout_conflictdata *conflict;
|
||||
size_t i;
|
||||
|
||||
if (data->opts_free_baseline) {
|
||||
git_tree_free(data->opts.baseline);
|
||||
data->opts.baseline = NULL;
|
||||
@ -1771,10 +1768,7 @@ static void checkout_data_clear(checkout_data *data)
|
||||
git_vector_free(&data->removes);
|
||||
git_pool_clear(&data->pool);
|
||||
|
||||
git_vector_foreach(&data->conflicts, i, conflict)
|
||||
git__free(conflict);
|
||||
|
||||
git_vector_free(&data->conflicts);
|
||||
git_vector_free_all(&data->conflicts);
|
||||
|
||||
git__free(data->pfx);
|
||||
data->pfx = NULL;
|
||||
|
@ -483,14 +483,7 @@ static int diff_list_apply_options(
|
||||
|
||||
static void diff_list_free(git_diff *diff)
|
||||
{
|
||||
git_diff_delta *delta;
|
||||
unsigned int i;
|
||||
|
||||
git_vector_foreach(&diff->deltas, i, delta) {
|
||||
git__free(delta);
|
||||
diff->deltas.contents[i] = NULL;
|
||||
}
|
||||
git_vector_free(&diff->deltas);
|
||||
git_vector_free_all(&diff->deltas);
|
||||
|
||||
git_pathspec__vfree(&diff->pathspec);
|
||||
git_pool_clear(&diff->pool);
|
||||
|
@ -209,9 +209,7 @@ int git_diff_merge(git_diff *onto, const git_diff *from)
|
||||
git_pool_strdup_safe(&onto->pool, onto->opts.new_prefix);
|
||||
}
|
||||
|
||||
git_vector_foreach(&onto_new, i, delta)
|
||||
git__free(delta);
|
||||
git_vector_free(&onto_new);
|
||||
git_vector_free_all(&onto_new);
|
||||
git_pool_clear(&onto_pool);
|
||||
|
||||
return error;
|
||||
@ -445,9 +443,7 @@ static int apply_splits_and_deletes(
|
||||
return 0;
|
||||
|
||||
on_error:
|
||||
git_vector_foreach(&onto, i, delta)
|
||||
git__free(delta);
|
||||
git_vector_free(&onto);
|
||||
git_vector_free_all(&onto);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -1005,30 +1005,20 @@ on_error:
|
||||
|
||||
void git_indexer_free(git_indexer *idx)
|
||||
{
|
||||
khiter_t k;
|
||||
unsigned int i;
|
||||
struct entry *e;
|
||||
struct delta_info *delta;
|
||||
|
||||
if (idx == NULL)
|
||||
return;
|
||||
|
||||
git_vector_foreach(&idx->objects, i, e)
|
||||
git__free(e);
|
||||
git_vector_free(&idx->objects);
|
||||
git_vector_free_all(&idx->objects);
|
||||
|
||||
if (idx->pack) {
|
||||
for (k = kh_begin(idx->pack->idx_cache); k != kh_end(idx->pack->idx_cache); k++) {
|
||||
if (kh_exist(idx->pack->idx_cache, k))
|
||||
git__free(kh_value(idx->pack->idx_cache, k));
|
||||
}
|
||||
struct git_pack_entry *pentry;
|
||||
kh_foreach_value(
|
||||
idx->pack->idx_cache, pentry, { git__free(pentry); });
|
||||
|
||||
git_oidmap_free(idx->pack->idx_cache);
|
||||
}
|
||||
|
||||
git_vector_foreach(&idx->deltas, i, delta)
|
||||
git__free(delta);
|
||||
git_vector_free(&idx->deltas);
|
||||
git_vector_free_all(&idx->deltas);
|
||||
git_packfile_free(idx->pack);
|
||||
git_filebuf_cleanup(&idx->pack_file);
|
||||
git__free(idx);
|
||||
|
@ -920,12 +920,7 @@ static fs_iterator_frame *fs_iterator__alloc_frame(fs_iterator *fi)
|
||||
|
||||
static void fs_iterator__free_frame(fs_iterator_frame *ff)
|
||||
{
|
||||
size_t i;
|
||||
git_path_with_stat *path;
|
||||
|
||||
git_vector_foreach(&ff->entries, i, path)
|
||||
git__free(path);
|
||||
git_vector_free(&ff->entries);
|
||||
git_vector_free_all(&ff->entries);
|
||||
git__free(ff);
|
||||
}
|
||||
|
||||
|
@ -2383,11 +2383,7 @@ done:
|
||||
git_index_set_caps(index_repo, index_repo_caps);
|
||||
|
||||
git_index_free(index_repo);
|
||||
|
||||
git_vector_foreach(&paths, i, path)
|
||||
git__free(path);
|
||||
|
||||
git_vector_free(&paths);
|
||||
git_vector_free_all(&paths);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@ -102,15 +102,7 @@ int git_pathspec__vinit(
|
||||
/* free data from the pathspec vector */
|
||||
void git_pathspec__vfree(git_vector *vspec)
|
||||
{
|
||||
git_attr_fnmatch *match;
|
||||
unsigned int i;
|
||||
|
||||
git_vector_foreach(vspec, i, match) {
|
||||
git__free(match);
|
||||
vspec->contents[i] = NULL;
|
||||
}
|
||||
|
||||
git_vector_free(vspec);
|
||||
git_vector_free_all(vspec);
|
||||
}
|
||||
|
||||
struct pathspec_match_context {
|
||||
|
@ -541,10 +541,7 @@ static int queue_objects(git_push *push)
|
||||
error = 0;
|
||||
|
||||
on_error:
|
||||
git_vector_foreach(&commits, i, oid)
|
||||
git__free(oid);
|
||||
|
||||
git_vector_free(&commits);
|
||||
git_vector_free_all(&commits);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
14
src/remote.c
14
src/remote.c
@ -1158,15 +1158,7 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo)
|
||||
error = giterr_restore(&data.error);
|
||||
|
||||
if (error < 0) {
|
||||
size_t i;
|
||||
char *elem;
|
||||
|
||||
git_vector_foreach(&data.list, i, elem) {
|
||||
git__free(elem);
|
||||
}
|
||||
|
||||
git_vector_free(&data.list);
|
||||
|
||||
git_vector_free_all(&data.list);
|
||||
return error;
|
||||
}
|
||||
|
||||
@ -1651,9 +1643,7 @@ static int copy_refspecs(git_strarray *array, git_remote *remote, unsigned int p
|
||||
return 0;
|
||||
|
||||
on_error:
|
||||
git_vector_foreach(&refspecs, i, dup)
|
||||
git__free(dup);
|
||||
git_vector_free(&refspecs);
|
||||
git_vector_free_all(&refspecs);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -376,19 +376,13 @@ const git_status_entry *git_status_byindex(git_status_list *status, size_t i)
|
||||
|
||||
void git_status_list_free(git_status_list *status)
|
||||
{
|
||||
git_status_entry *status_entry;
|
||||
size_t i;
|
||||
|
||||
if (status == NULL)
|
||||
return;
|
||||
|
||||
git_diff_free(status->head2idx);
|
||||
git_diff_free(status->idx2wd);
|
||||
|
||||
git_vector_foreach(&status->paired, i, status_entry)
|
||||
git__free(status_entry);
|
||||
|
||||
git_vector_free(&status->paired);
|
||||
git_vector_free_all(&status->paired);
|
||||
|
||||
git__memzero(status, sizeof(*status));
|
||||
git__free(status);
|
||||
|
14
src/vector.c
14
src/vector.c
@ -77,6 +77,20 @@ void git_vector_free(git_vector *v)
|
||||
v->_alloc_size = 0;
|
||||
}
|
||||
|
||||
void git_vector_free_all(git_vector *v)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
assert(v);
|
||||
|
||||
for (i = 0; i < v->length; ++i) {
|
||||
git__free(v->contents[i]);
|
||||
v->contents[i] = NULL;
|
||||
}
|
||||
|
||||
git_vector_free(v);
|
||||
}
|
||||
|
||||
int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp)
|
||||
{
|
||||
assert(v);
|
||||
|
@ -23,6 +23,7 @@ typedef struct git_vector {
|
||||
|
||||
int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp);
|
||||
void git_vector_free(git_vector *v);
|
||||
void git_vector_free_all(git_vector *v); /* free each entry and self */
|
||||
void git_vector_clear(git_vector *v);
|
||||
int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp);
|
||||
void git_vector_swap(git_vector *a, git_vector *b);
|
||||
|
Loading…
Reference in New Issue
Block a user