void test_core_strmap__0(void) { git_strmap *table = git_strmap_alloc(); cl_assert(table != NULL); cl_assert(git_strmap_num_entries(table) == 0); git_strmap_free(table); }
int git_transaction_new(git_transaction **out, git_repository *repo) { int error; git_pool pool; git_transaction *tx = NULL; assert(out && repo); if ((error = git_pool_init(&pool, 1, 0)) < 0) return error; tx = git_pool_mallocz(&pool, sizeof(git_transaction)); if (!tx) { error = -1; goto on_error; } if ((error = git_strmap_alloc(&tx->locks)) < 0) { error = -1; goto on_error; } if ((error = git_repository_refdb(&tx->db, repo)) < 0) goto on_error; memcpy(&tx->pool, &pool, sizeof(git_pool)); tx->repo = repo; *out = tx; return 0; on_error: git_pool_clear(&pool); return error; }
git_diff_driver_registry *git_diff_driver_registry_new() { git_diff_driver_registry *reg = git__calloc(1, sizeof(git_diff_driver_registry)); if (!reg) return NULL; if (git_strmap_alloc(®->drivers) < 0) { git_diff_driver_registry_free(reg); return NULL; } return reg; }
void test_core_strmap__1(void) { int i; char *str; git_strmap *table = git_strmap_alloc(); cl_assert(table != NULL); insert_strings(table, 20); cl_assert(git_strmap_exists(table, "aaaaaaaaa")); cl_assert(git_strmap_exists(table, "ggggggggg")); cl_assert(!git_strmap_exists(table, "aaaaaaaab")); cl_assert(!git_strmap_exists(table, "abcdefghi")); i = 0; git_strmap_foreach_value(table, str, { i++; free(str); });
int git_sortedcache_new( git_sortedcache **out, size_t item_path_offset, git_sortedcache_free_item_fn free_item, void *free_item_payload, git_vector_cmp item_cmp, const char *path) { git_sortedcache *sc; size_t pathlen; pathlen = path ? strlen(path) : 0; sc = (git_sortedcache *) git__calloc(sizeof(git_sortedcache) + pathlen + 1, 1); GITERR_CHECK_ALLOC(sc); if (git_pool_init(&sc->pool, 1, 0) < 0 || git_vector_init(&sc->items, 4, item_cmp) < 0 || git_strmap_alloc(&sc->map) < 0) goto fail; if (git_rwlock_init(&sc->lock)) { giterr_set(GITERR_OS, "Failed to initialize lock"); goto fail; } sc->item_path_offset = item_path_offset; sc->free_item = free_item; sc->free_item_payload = free_item_payload; GIT_REFCOUNT_INC(sc); if (pathlen) memcpy(sc->path, path, pathlen); *out = sc; return 0; fail: git_strmap_free(sc->map); git_vector_free(&sc->items); git_pool_clear(&sc->pool); git__free(sc); return -1; }
void test_core_strmap__initialize(void) { cl_git_pass(git_strmap_alloc(&g_table)); cl_assert(g_table != NULL); }