test_must_be_empty: simplify file existence check
[git/debian.git] / oidset.c
blob454c54f93396efccfb9957423931d0ea727ff340
1 #include "cache.h"
2 #include "oidset.h"
4 int oidset_contains(const struct oidset *set, const struct object_id *oid)
6 if (!set->map.map.tablesize)
7 return 0;
8 return !!oidmap_get(&set->map, oid);
11 int oidset_insert(struct oidset *set, const struct object_id *oid)
13 struct oidmap_entry *entry;
15 if (!set->map.map.tablesize)
16 oidmap_init(&set->map, 0);
17 else if (oidset_contains(set, oid))
18 return 1;
20 entry = xmalloc(sizeof(*entry));
21 oidcpy(&entry->oid, oid);
23 oidmap_put(&set->map, entry);
24 return 0;
27 int oidset_remove(struct oidset *set, const struct object_id *oid)
29 struct oidmap_entry *entry;
31 entry = oidmap_remove(&set->map, oid);
32 free(entry);
34 return (entry != NULL);
37 void oidset_clear(struct oidset *set)
39 oidmap_free(&set->map, 1);