Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 232a7e3

Browse files
author
Vicent Marti
committed
Merge pull request libgit2#3488 from libgit2/vmg/pool
pool: Simplify implementation
2 parents efc659b + d845abe commit 232a7e3

19 files changed

+102
-354
lines changed

src/attr_file.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ int git_attr_file__new(
3535
return -1;
3636
}
3737

38-
if (git_pool_init(&attrs->pool, 1, 0) < 0) {
39-
attr_file_free(attrs);
40-
return -1;
41-
}
42-
38+
git_pool_init(&attrs->pool, 1);
4339
GIT_REFCOUNT_INC(attrs);
4440
attrs->entry = entry;
4541
attrs->source = source;

src/attrcache.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,11 @@ int git_attr_cache__do_init(git_repository *repo)
388388
* hashtable for attribute macros, and string pool
389389
*/
390390
if ((ret = git_strmap_alloc(&cache->files)) < 0 ||
391-
(ret = git_strmap_alloc(&cache->macros)) < 0 ||
392-
(ret = git_pool_init(&cache->pool, 1, 0)) < 0)
391+
(ret = git_strmap_alloc(&cache->macros)) < 0)
393392
goto cancel;
394393

394+
git_pool_init(&cache->pool, 1);
395+
395396
cache = git__compare_and_swap(&repo->attrcache, NULL, cache);
396397
if (cache)
397398
goto cancel; /* raced with another thread, free this but no error */

src/checkout.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,11 +1255,13 @@ static int checkout_get_actions(
12551255
int error = 0, act;
12561256
const git_index_entry *wditem;
12571257
git_vector pathspec = GIT_VECTOR_INIT, *deltas;
1258-
git_pool pathpool = GIT_POOL_INIT_STRINGPOOL;
1258+
git_pool pathpool;
12591259
git_diff_delta *delta;
12601260
size_t i, *counts = NULL;
12611261
uint32_t *actions = NULL;
12621262

1263+
git_pool_init(&pathpool, 1);
1264+
12631265
if (data->opts.paths.count > 0 &&
12641266
git_pathspec__vinit(&pathspec, &data->opts.paths, &pathpool) < 0)
12651267
return -1;
@@ -2439,10 +2441,11 @@ static int checkout_data_init(
24392441
git_config_entry_free(conflict_style);
24402442
}
24412443

2444+
git_pool_init(&data->pool, 1);
2445+
24422446
if ((error = git_vector_init(&data->removes, 0, git__strcmp_cb)) < 0 ||
24432447
(error = git_vector_init(&data->remove_conflicts, 0, NULL)) < 0 ||
24442448
(error = git_vector_init(&data->update_conflicts, 0, NULL)) < 0 ||
2445-
(error = git_pool_init(&data->pool, 1, 0)) < 0 ||
24462449
(error = git_buf_puts(&data->path, data->opts.target_directory)) < 0 ||
24472450
(error = git_path_to_dir(&data->path)) < 0 ||
24482451
(error = git_strmap_alloc(&data->mkdir_map)) < 0)

src/commit_list.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ git_commit_list *git_commit_list_insert_by_date(git_commit_list_node *item, git_
4747

4848
git_commit_list_node *git_commit_list_alloc_node(git_revwalk *walk)
4949
{
50-
return (git_commit_list_node *)git_pool_malloc(&walk->commit_pool, COMMIT_ALLOC);
50+
return (git_commit_list_node *)git_pool_mallocz(&walk->commit_pool, 1);
5151
}
5252

5353
static int commit_error(git_commit_list_node *commit, const char *msg)

src/diff.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,9 @@ static git_diff *diff_list_alloc(
430430
diff->new_src = new_iter->type;
431431
memcpy(&diff->opts, &dflt, sizeof(diff->opts));
432432

433-
if (git_vector_init(&diff->deltas, 0, git_diff_delta__cmp) < 0 ||
434-
git_pool_init(&diff->pool, 1, 0) < 0) {
433+
git_pool_init(&diff->pool, 1);
434+
435+
if (git_vector_init(&diff->deltas, 0, git_diff_delta__cmp) < 0) {
435436
git_diff_free(diff);
436437
return NULL;
437438
}

src/diff_tform.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ int git_diff__merge(
134134
return -1;
135135
}
136136

137-
if (git_vector_init(
138-
&onto_new, onto->deltas.length, git_diff_delta__cmp) < 0 ||
139-
git_pool_init(&onto_pool, 1, 0) < 0)
137+
if (git_vector_init(&onto_new, onto->deltas.length, git_diff_delta__cmp) < 0)
140138
return -1;
141139

140+
git_pool_init(&onto_pool, 1);
141+
142142
for (i = 0, j = 0; i < onto->deltas.length || j < from->deltas.length; ) {
143143
git_diff_delta *o = GIT_VECTOR_GET(&onto->deltas, i);
144144
const git_diff_delta *f = GIT_VECTOR_GET(&from->deltas, j);

src/index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ int git_index_open(git_index **index_out, const char *index_path)
439439
return -1;
440440
}
441441

442-
git_pool_init(&index->tree_pool, 1, 0);
442+
git_pool_init(&index->tree_pool, 1);
443443

444444
if (index_path != NULL) {
445445
index->index_file_path = git__strdup(index_path);

src/iterator.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ static bool tree_iterator__pop_frame(tree_iterator *ti, bool final)
567567
tree_iterator__move_to_next(ti, tf);
568568

569569
if (!final) { /* if final, don't bother to clean up */
570-
git_pool_free_array(&ti->pool, tf->n_entries, (void **)tf->entries);
570+
// TODO: maybe free the pool so far?
571571
git_buf_rtruncate_at_char(&ti->path, '/');
572572
}
573573

@@ -822,8 +822,9 @@ int git_iterator_for_tree(
822822
if ((error = iterator__update_ignore_case((git_iterator *)ti, options ? options->flags : 0)) < 0)
823823
goto fail;
824824

825-
if ((error = git_pool_init(&ti->pool, sizeof(tree_iterator_entry),0)) < 0 ||
826-
(error = tree_iterator__create_root_frame(ti, tree)) < 0 ||
825+
git_pool_init(&ti->pool, sizeof(tree_iterator_entry));
826+
827+
if ((error = tree_iterator__create_root_frame(ti, tree)) < 0 ||
827828
(error = tree_iterator__push_frame(ti)) < 0) /* expand root now */
828829
goto fail;
829830

src/merge.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ static int merge_conflict_resolve_automerge(
711711
(error = git_odb_write(&automerge_oid, odb, result.ptr, result.len, GIT_OBJ_BLOB)) < 0)
712712
goto done;
713713

714-
if ((index_entry = git_pool_malloc(&diff_list->pool, sizeof(git_index_entry))) == NULL)
714+
if ((index_entry = git_pool_mallocz(&diff_list->pool, sizeof(git_index_entry))) == NULL)
715715
GITERR_CHECK_ALLOC(index_entry);
716716

717717
index_entry->path = git_pool_strdup(&diff_list->pool, result.path);
@@ -1307,7 +1307,6 @@ GIT_INLINE(int) index_entry_dup_pool(
13071307
{
13081308
if (src != NULL) {
13091309
memcpy(out, src, sizeof(git_index_entry));
1310-
13111310
if ((out->path = git_pool_strdup(pool, src->path)) == NULL)
13121311
return -1;
13131312
}
@@ -1343,7 +1342,7 @@ static git_merge_diff *merge_diff_from_index_entries(
13431342
git_merge_diff *conflict;
13441343
git_pool *pool = &diff_list->pool;
13451344

1346-
if ((conflict = git_pool_malloc(pool, sizeof(git_merge_diff))) == NULL)
1345+
if ((conflict = git_pool_mallocz(pool, sizeof(git_merge_diff))) == NULL)
13471346
return NULL;
13481347

13491348
if (index_entry_dup_pool(&conflict->ancestor_entry, pool, entries[TREE_IDX_ANCESTOR]) < 0 ||
@@ -1442,10 +1441,11 @@ git_merge_diff_list *git_merge_diff_list__alloc(git_repository *repo)
14421441

14431442
diff_list->repo = repo;
14441443

1444+
git_pool_init(&diff_list->pool, 1);
1445+
14451446
if (git_vector_init(&diff_list->staged, 0, NULL) < 0 ||
14461447
git_vector_init(&diff_list->conflicts, 0, NULL) < 0 ||
1447-
git_vector_init(&diff_list->resolved, 0, NULL) < 0 ||
1448-
git_pool_init(&diff_list->pool, 1, 0) < 0) {
1448+
git_vector_init(&diff_list->resolved, 0, NULL) < 0) {
14491449
git_merge_diff_list__free(diff_list);
14501450
return NULL;
14511451
}

src/pack-objects.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
135135
if (!pb->walk_objects)
136136
goto on_error;
137137

138-
if (git_pool_init(&pb->object_pool, sizeof(git_walk_object), 0) < 0)
139-
goto on_error;
138+
git_pool_init(&pb->object_pool, sizeof(git_walk_object));
140139

141140
pb->repo = repo;
142141
pb->nr_threads = 1; /* do not spawn any thread by default */

src/pathspec.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ int git_pathspec__init(git_pathspec *ps, const git_strarray *paths)
237237
memset(ps, 0, sizeof(*ps));
238238

239239
ps->prefix = git_pathspec_prefix(paths);
240+
git_pool_init(&ps->pool, 1);
240241

241-
if ((error = git_pool_init(&ps->pool, 1, 0)) < 0 ||
242-
(error = git_pathspec__vinit(&ps->pathspec, paths, &ps->pool)) < 0)
242+
if ((error = git_pathspec__vinit(&ps->pathspec, paths, &ps->pool)) < 0)
243243
git_pathspec__clear(ps);
244244

245245
return error;
@@ -312,15 +312,11 @@ static git_pathspec_match_list *pathspec_match_alloc(
312312
git_pathspec *ps, int datatype)
313313
{
314314
git_pathspec_match_list *m = git__calloc(1, sizeof(git_pathspec_match_list));
315-
316-
if (m != NULL && git_pool_init(&m->pool, 1, 0) < 0) {
317-
pathspec_match_free(m);
318-
m = NULL;
319-
}
320-
321315
if (!m)
322316
return NULL;
323317

318+
git_pool_init(&m->pool, 1);
319+
324320
/* need to keep reference to pathspec and increment refcount because
325321
* failures array stores pointers to the pattern strings of the
326322
* pathspec that had no matches

0 commit comments

Comments
 (0)