1 #include "git-compat-util.h"
6 void oidset_init(struct oidset
*set
, size_t initial_size
)
8 memset(&set
->set
, 0, sizeof(set
->set
));
10 kh_resize_oid_set(&set
->set
, initial_size
);
13 int oidset_contains(const struct oidset
*set
, const struct object_id
*oid
)
15 khiter_t pos
= kh_get_oid_set(&set
->set
, *oid
);
16 return pos
!= kh_end(&set
->set
);
19 int oidset_insert(struct oidset
*set
, const struct object_id
*oid
)
22 kh_put_oid_set(&set
->set
, *oid
, &added
);
26 int oidset_remove(struct oidset
*set
, const struct object_id
*oid
)
28 khiter_t pos
= kh_get_oid_set(&set
->set
, *oid
);
29 if (pos
== kh_end(&set
->set
))
31 kh_del_oid_set(&set
->set
, pos
);
35 void oidset_clear(struct oidset
*set
)
37 kh_release_oid_set(&set
->set
);
41 void oidset_parse_file(struct oidset
*set
, const char *path
)
43 oidset_parse_file_carefully(set
, path
, NULL
, NULL
);
46 void oidset_parse_file_carefully(struct oidset
*set
, const char *path
,
47 oidset_parse_tweak_fn fn
, void *cbdata
)
50 struct strbuf sb
= STRBUF_INIT
;
53 fp
= fopen(path
, "r");
55 die("could not open object name list: %s", path
);
56 while (!strbuf_getline(&sb
, fp
)) {
61 * Allow trailing comments, leading whitespace
62 * (including before commits), and empty or whitespace
65 name
= strchr(sb
.buf
, '#');
67 strbuf_setlen(&sb
, name
- sb
.buf
);
72 if (parse_oid_hex(sb
.buf
, &oid
, &p
) || *p
!= '\0')
73 die("invalid object name: %s", sb
.buf
);
74 if (fn
&& fn(&oid
, cbdata
))
76 oidset_insert(set
, &oid
);
79 die_errno("Could not read '%s'", path
);