2017-02-08 21:53:07 +01:00
|
|
|
#include "cache.h"
|
|
|
|
#include "oidset.h"
|
|
|
|
|
|
|
|
int oidset_contains(const struct oidset *set, const struct object_id *oid)
|
|
|
|
{
|
2017-09-30 00:54:22 +02:00
|
|
|
if (!set->map.map.tablesize)
|
2017-02-08 21:53:07 +01:00
|
|
|
return 0;
|
2017-09-30 00:54:22 +02:00
|
|
|
return !!oidmap_get(&set->map, oid);
|
2017-02-08 21:53:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int oidset_insert(struct oidset *set, const struct object_id *oid)
|
|
|
|
{
|
2017-09-30 00:54:22 +02:00
|
|
|
struct oidmap_entry *entry;
|
2017-02-08 21:53:07 +01:00
|
|
|
|
2017-09-30 00:54:22 +02:00
|
|
|
if (!set->map.map.tablesize)
|
|
|
|
oidmap_init(&set->map, 0);
|
|
|
|
else if (oidset_contains(set, oid))
|
2017-02-08 21:53:07 +01:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
entry = xmalloc(sizeof(*entry));
|
|
|
|
oidcpy(&entry->oid, oid);
|
|
|
|
|
2017-09-30 00:54:22 +02:00
|
|
|
oidmap_put(&set->map, entry);
|
2017-02-08 21:53:07 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-21 21:58:49 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-02-08 21:53:07 +01:00
|
|
|
void oidset_clear(struct oidset *set)
|
|
|
|
{
|
2017-09-30 00:54:22 +02:00
|
|
|
oidmap_free(&set->map, 1);
|
2017-02-08 21:53:07 +01:00
|
|
|
}
|