oidset.c 767 Bytes
Newer Older
Jeff King's avatar
Jeff King committed
1 2 3 4 5
#include "cache.h"
#include "oidset.h"

int oidset_contains(const struct oidset *set, const struct object_id *oid)
{
Jonathan Tan's avatar
Jonathan Tan committed
6
	if (!set->map.map.tablesize)
Jeff King's avatar
Jeff King committed
7
		return 0;
Jonathan Tan's avatar
Jonathan Tan committed
8
	return !!oidmap_get(&set->map, oid);
Jeff King's avatar
Jeff King committed
9 10 11 12
}

int oidset_insert(struct oidset *set, const struct object_id *oid)
{
Jonathan Tan's avatar
Jonathan Tan committed
13
	struct oidmap_entry *entry;
Jeff King's avatar
Jeff King committed
14

Jonathan Tan's avatar
Jonathan Tan committed
15 16 17
	if (!set->map.map.tablesize)
		oidmap_init(&set->map, 0);
	else if (oidset_contains(set, oid))
Jeff King's avatar
Jeff King committed
18 19 20 21 22
		return 1;

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

Jonathan Tan's avatar
Jonathan Tan committed
23
	oidmap_put(&set->map, entry);
Jeff King's avatar
Jeff King committed
24 25 26
	return 0;
}

27 28 29 30 31 32 33 34 35 36
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);
}

Jeff King's avatar
Jeff King committed
37 38
void oidset_clear(struct oidset *set)
{
Jonathan Tan's avatar
Jonathan Tan committed
39
	oidmap_free(&set->map, 1);
Jeff King's avatar
Jeff King committed
40
}