4 void oidset_init(struct oidset
*set
, size_t initial_size
)
6 memset(&set
->set
, 0, sizeof(set
->set
));
8 kh_resize_oid_set(&set
->set
, initial_size
);
11 int oidset_contains(const struct oidset
*set
, const struct object_id
*oid
)
13 khiter_t pos
= kh_get_oid_set(&set
->set
, *oid
);
14 return pos
!= kh_end(&set
->set
);
17 int oidset_insert(struct oidset
*set
, const struct object_id
*oid
)
20 kh_put_oid_set(&set
->set
, *oid
, &added
);
24 int oidset_remove(struct oidset
*set
, const struct object_id
*oid
)
26 khiter_t pos
= kh_get_oid_set(&set
->set
, *oid
);
27 if (pos
== kh_end(&set
->set
))
29 kh_del_oid_set(&set
->set
, pos
);
33 void oidset_clear(struct oidset
*set
)
35 kh_release_oid_set(&set
->set
);
39 void oidset_parse_file(struct oidset
*set
, const char *path
)
41 oidset_parse_file_carefully(set
, path
, NULL
, NULL
);
44 void oidset_parse_file_carefully(struct oidset
*set
, const char *path
,
45 oidset_parse_tweak_fn fn
, void *cbdata
)
48 struct strbuf sb
= STRBUF_INIT
;
51 fp
= fopen(path
, "r");
53 die("could not open object name list: %s", path
);
54 while (!strbuf_getline(&sb
, fp
)) {
59 * Allow trailing comments, leading whitespace
60 * (including before commits), and empty or whitespace
63 name
= strchr(sb
.buf
, '#');
65 strbuf_setlen(&sb
, name
- sb
.buf
);
70 if (parse_oid_hex(sb
.buf
, &oid
, &p
) || *p
!= '\0')
71 die("invalid object name: %s", sb
.buf
);
72 if (fn
&& fn(&oid
, cbdata
))
74 oidset_insert(set
, &oid
);
77 die_errno("Could not read '%s'", path
);