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 void oidset_insert_from_set(struct oidset
*dest
, struct oidset
*src
)
28 struct oidset_iter iter
;
29 struct object_id
*src_oid
;
31 oidset_iter_init(src
, &iter
);
32 while ((src_oid
= oidset_iter_next(&iter
)))
33 oidset_insert(dest
, src_oid
);
36 int oidset_remove(struct oidset
*set
, const struct object_id
*oid
)
38 khiter_t pos
= kh_get_oid_set(&set
->set
, *oid
);
39 if (pos
== kh_end(&set
->set
))
41 kh_del_oid_set(&set
->set
, pos
);
45 void oidset_clear(struct oidset
*set
)
47 kh_release_oid_set(&set
->set
);
51 void oidset_parse_file(struct oidset
*set
, const char *path
)
53 oidset_parse_file_carefully(set
, path
, NULL
, NULL
);
56 void oidset_parse_file_carefully(struct oidset
*set
, const char *path
,
57 oidset_parse_tweak_fn fn
, void *cbdata
)
60 struct strbuf sb
= STRBUF_INIT
;
63 fp
= fopen(path
, "r");
65 die("could not open object name list: %s", path
);
66 while (!strbuf_getline(&sb
, fp
)) {
71 * Allow trailing comments, leading whitespace
72 * (including before commits), and empty or whitespace
75 name
= strchr(sb
.buf
, '#');
77 strbuf_setlen(&sb
, name
- sb
.buf
);
82 if (parse_oid_hex(sb
.buf
, &oid
, &p
) || *p
!= '\0')
83 die("invalid object name: %s", sb
.buf
);
84 if (fn
&& fn(&oid
, cbdata
))
86 oidset_insert(set
, &oid
);
89 die_errno("Could not read '%s'", path
);