]> git.ipfire.org Git - thirdparty/git.git/blame_incremental - oidset.c
refs/packed-backend: express constants using the_hash_algo
[thirdparty/git.git] / oidset.c
... / ...
CommitLineData
1#include "cache.h"
2#include "oidset.h"
3
4int 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
11int 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
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
37void oidset_clear(struct oidset *set)
38{
39 oidmap_free(&set->map, 1);
40}