Staging
v0.5.1
swh:1:snp:c5feb7ee9221a3820c8879e85e8a18470c0b3afa
Raw File
Tip revision: 98cdfbb84ad2ed6a2eb43dafa357a70a4b0a0fad authored by Junio C Hamano on 21 November 2018, 14:22:12 UTC
Git 2.19.2
Tip revision: 98cdfbb
oidset.c
#include "cache.h"
#include "oidset.h"

int oidset_contains(const struct oidset *set, const struct object_id *oid)
{
	if (!set->map.map.tablesize)
		return 0;
	return !!oidmap_get(&set->map, oid);
}

int oidset_insert(struct oidset *set, const struct object_id *oid)
{
	struct oidmap_entry *entry;

	if (!set->map.map.tablesize)
		oidmap_init(&set->map, 0);
	else if (oidset_contains(set, oid))
		return 1;

	entry = xmalloc(sizeof(*entry));
	oidcpy(&entry->oid, oid);

	oidmap_put(&set->map, entry);
	return 0;
}

int oidset_remove(struct oidset *set, const struct object_id *oid)
{
	struct oidmap_entry *entry;

	entry = oidmap_remove(&set->map, oid);
	free(entry);

	return (entry != NULL);
}

void oidset_clear(struct oidset *set)
{
	oidmap_free(&set->map, 1);
}
back to top