Esempio n. 1
0
void *git_cache_try_store(git_cache *cache, void *entry)
{
	uint32_t hash;
	const git_oid *oid;
	cache_node *node = NULL;

	oid = &((git_cached_obj*)entry)->oid;
	memcpy(&hash, oid->id, sizeof(hash));
	node = &cache->nodes[hash & cache->size_mask];

	/* increase the refcount on this object, because
	 * the cache now owns it */
	git_cached_obj_incref(entry);
	git_mutex_lock(&node->lock);

	if (node->ptr == NULL) {
		node->ptr = entry;
	} else if (git_cached_obj_compare(node->ptr, oid) == 0) {
		git_cached_obj_decref(entry, cache->free_obj);
		entry = node->ptr;
	} else {
		git_cached_obj_decref(node->ptr, cache->free_obj);
		node->ptr = entry;
	}

	/* increase the refcount again, because we are
	 * returning it to the user */
	git_cached_obj_incref(entry);
	git_mutex_unlock(&node->lock);

	return entry;
}
Esempio n. 2
0
int git_blob__parse(git_blob *blob, git_odb_object *odb_obj)
{
	assert(blob);
	git_cached_obj_incref((git_cached_obj *)odb_obj);
	blob->odb_object = odb_obj;
	return GIT_SUCCESS;
}
Esempio n. 3
0
int git_blob__parse(void *blob, git_odb_object *odb_obj)
{
	assert(blob);
	git_cached_obj_incref((git_cached_obj *)odb_obj);
	((git_blob *)blob)->odb_object = odb_obj;
	return 0;
}
Esempio n. 4
0
int git_blob__parse(void *_blob, git_odb_object *odb_obj)
{
	git_blob *blob = (git_blob *) _blob;
	assert(blob);
	git_cached_obj_incref((git_cached_obj *)odb_obj);
	blob->raw = 0;
	blob->data.odb = odb_obj;
	return 0;
}
Esempio n. 5
0
void *git_cache_get(git_cache *cache, const git_oid *oid)
{
	uint32_t hash;
	cache_node *node = NULL;
	void *result = NULL;

	memcpy(&hash, oid->id, sizeof(hash));
	node = &cache->nodes[hash & cache->size_mask];

	git_mutex_lock(&node->lock);
	{
		if (node->ptr && git_cached_obj_compare(node->ptr, oid) == 0) {
			git_cached_obj_incref(node->ptr);
			result = node->ptr;
		}
	}
	git_mutex_unlock(&node->lock);

	return result;
}
Esempio n. 6
0
int git_object_dup(git_object **dest, git_object *source)
{
	git_cached_obj_incref(source);
	*dest = source;
	return 0;
}