]> git.ipfire.org Git - thirdparty/git.git/blame - oidset.c
t5318: avoid unnecessary command substitutions
[thirdparty/git.git] / oidset.c
CommitLineData
29c2bd5f
JK
1#include "cache.h"
2#include "oidset.h"
3
29c2bd5f
JK
4int oidset_contains(const struct oidset *set, const struct object_id *oid)
5{
9e6fabde 6 if (!set->map.map.tablesize)
29c2bd5f 7 return 0;
9e6fabde 8 return !!oidmap_get(&set->map, oid);
29c2bd5f
JK
9}
10
11int oidset_insert(struct oidset *set, const struct object_id *oid)
12{
9e6fabde 13 struct oidmap_entry *entry;
29c2bd5f 14
9e6fabde
JT
15 if (!set->map.map.tablesize)
16 oidmap_init(&set->map, 0);
17 else if (oidset_contains(set, oid))
29c2bd5f
JK
18 return 1;
19
20 entry = xmalloc(sizeof(*entry));
29c2bd5f
JK
21 oidcpy(&entry->oid, oid);
22
9e6fabde 23 oidmap_put(&set->map, entry);
29c2bd5f
JK
24 return 0;
25}
26
c3a9ad31
JH
27int oidset_remove(struct oidset *set, const struct object_id *oid)
28{
29 struct oidmap_entry *entry;
30
31 entry = oidmap_remove(&set->map, oid);
32 free(entry);
33
34 return (entry != NULL);
35}
36
29c2bd5f
JK
37void oidset_clear(struct oidset *set)
38{
9e6fabde 39 oidmap_free(&set->map, 1);
29c2bd5f 40}