Exemplo n.º 1
0
static git_repository *repository_alloc()
{
	git_repository *repo = git__malloc(sizeof(git_repository));
	if (!repo)
		return NULL;

	memset(repo, 0x0, sizeof(git_repository));

	repo->objects = git_hashtable_alloc(
			OBJECT_TABLE_SIZE, 
			object_table_hash,
			object_table_hashkey);

	if (repo->objects == NULL) {
		free(repo);
		return NULL;
	}

	if (git_repository__refcache_init(&repo->references) < GIT_SUCCESS) {
		git_hashtable_free(repo->objects);
		free(repo);
		return NULL;
	}

	return repo;
}
Exemplo n.º 2
0
int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo)
{
	git_revwalk *walk;

	walk = git__malloc(sizeof(git_revwalk));
	if (walk == NULL)
		return GIT_ENOMEM;

	memset(walk, 0x0, sizeof(git_revwalk));

	walk->commits = git_hashtable_alloc(64,
			object_table_hash,
			(git_hash_keyeq_ptr)git_oid_cmp);

	if (walk->commits == NULL) {
		free(walk);
		return GIT_ENOMEM;
	}

	git_pqueue_init(&walk->iterator_time, 8, commit_time_cmp);
	git_vector_init(&walk->memory_alloc, 8, NULL);
	alloc_chunk(walk);

	walk->get_next = &revwalk_next_unsorted;
	walk->enqueue = &revwalk_enqueue_unsorted;

	walk->repo = repo;

	*revwalk_out = walk;
	return GIT_SUCCESS;
}
Exemplo n.º 3
0
static git_repository *repository_alloc()
{
	git_repository *repo = git__malloc(sizeof(git_repository));
	if (!repo)
		return NULL;

	memset(repo, 0x0, sizeof(git_repository));

	repo->objects = git_hashtable_alloc(
			OBJECT_TABLE_SIZE, 
			object_table_hash,
			object_table_hashkey);

	if (repo->objects == NULL) {
		free(repo);
		return NULL;
	}

	return repo;
}
Exemplo n.º 4
0
git_repository *git_repository__alloc()
{
	git_repository *repo = git__malloc(sizeof(git_repository));
	if (!repo)
		return NULL;

	memset(repo, 0x0, sizeof(git_repository));

	repo->objects = git_hashtable_alloc(
			default_table_size, 
			git__objtable_hash,
			git__objtable_haskey);

	if (repo->objects == NULL) {
		free(repo);
		return NULL;
	}

	return repo;
}
Exemplo n.º 5
0
int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo)
{
	git_revwalk *walk;

	walk = git__malloc(sizeof(git_revwalk));
	if (walk == NULL)
		return GIT_ENOMEM;

	memset(walk, 0x0, sizeof(git_revwalk));

	walk->commits = git_hashtable_alloc(64,
			git_revwalk__commit_hash,
			git_revwalk__commit_keycmp);

	if (walk->commits == NULL) {
		free(walk);
		return GIT_ENOMEM;
	}

	walk->repo = repo;

	*revwalk_out = walk;
	return GIT_SUCCESS;
}
Exemplo n.º 6
0
	oid = (git_oid *)key;

	return (git_oid_cmp(oid, &obj->id) == 0);
}


BEGIN_TEST(table_iterator)

	const int objects_n = 32;
	int i;
	table_item *objects, *ob;

	git_hashtable *table = NULL;
	git_hashtable_iterator iterator;

	table = git_hashtable_alloc(objects_n * 2, hash_func, hash_haskey);
	must_be_true(table != NULL);

	objects = git__malloc(objects_n * sizeof(table_item));
	memset(objects, 0x0, objects_n * sizeof(table_item));

	/* populate the hash table */
	for (i = 0; i < objects_n; ++i) {
		git_hash_buf(&(objects[i].id), &i, sizeof(int));
		must_pass(git_hashtable_insert(table, &(objects[i].id), &(objects[i])));
	}

	git_hashtable_iterator_init(table, &iterator);

	/* iterate through all nodes, mark as visited */
	while ((ob = (table_item *)git_hashtable_iterator_next(&iterator)) != NULL)
Exemplo n.º 7
0
	id = (git_oid *)key;
	memcpy(&r, id->id + (hash_id * sizeof(uint32_t)), sizeof(r));
	return r;
}

int hash_cmpkey(const void *a, const void *b)
{
	return git_oid_cmp(a, b);
}

BEGIN_TEST("table", table_create)

	git_hashtable *table = NULL;

	table = git_hashtable_alloc(55, hash_func, hash_cmpkey);
	must_be_true(table != NULL);
	must_be_true(table->size_mask + 1 == 64);

	git_hashtable_free(table);

END_TEST

BEGIN_TEST("table", table_populate)

	const int objects_n = 32;
	int i;

	table_item *objects;
	git_hashtable *table = NULL;