Merge branch 'mh/avoid-rewriting-packed-refs' into maint
[git] / oidset.c
1 #include "cache.h"
2 #include "oidset.h"
3
4 int oidset_contains(const struct oidset *set, const struct object_id *oid)
5 {
6         if (!set->map.map.tablesize)
7                 return 0;
8         return !!oidmap_get(&set->map, oid);
9 }
10
11 int oidset_insert(struct oidset *set, const struct object_id *oid)
12 {
13         struct oidmap_entry *entry;
14
15         if (!set->map.map.tablesize)
16                 oidmap_init(&set->map, 0);
17         else if (oidset_contains(set, oid))
18                 return 1;
19
20         entry = xmalloc(sizeof(*entry));
21         oidcpy(&entry->oid, oid);
22
23         oidmap_put(&set->map, entry);
24         return 0;
25 }
26
27 void oidset_clear(struct oidset *set)
28 {
29         oidmap_free(&set->map, 1);
30 }