Move oidset_parse_file() to oidset.c

Signed-off-by: Barret Rhoden <brho@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Barret Rhoden committed May 15, 2019 at 17:44 UTC f93895f8fcf1a45e594cd28c03b88a057382dc6b
3 files changed +43 -35
fsck.c
-35
@@ -181,41 +181,6 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,
181 return msg_type;
182 }
183
184 -void oidset_parse_file(struct oidset *set, const char *path)
185 -{
186 - FILE *fp;
187 - struct strbuf sb = STRBUF_INIT;
188 - struct object_id oid;
189 -
190 - fp = fopen(path, "r");
191 - if (!fp)
192 - die("could not open object name list: %s", path);
193 - while (!strbuf_getline(&sb, fp)) {
194 - const char *p;
195 - const char *name;
196 -
197 - /*
198 - * Allow trailing comments, leading whitespace
199 - * (including before commits), and empty or whitespace
200 - * only lines.
201 - */
202 - name = strchr(sb.buf, '#');
203 - if (name)
204 - strbuf_setlen(&sb, name - sb.buf);
205 - strbuf_trim(&sb);
206 - if (!sb.len)
207 - continue;
208 -
209 - if (parse_oid_hex(sb.buf, &oid, &p) || *p != '\0')
210 - die("invalid object name: %s", sb.buf);
211 - oidset_insert(set, &oid);
212 - }
213 - if (ferror(fp))
214 - die_errno("Could not read '%s'", path);
215 - fclose(fp);
216 - strbuf_release(&sb);
217 -}
218 -
184 static int parse_msg_type(const char *str)
185 {
186 if (!strcmp(str, "error"))
oidset.c
+35
@@ -35,3 +35,38 @@ void oidset_clear(struct oidset *set)
35 kh_release_oid(&set->set);
36 oidset_init(set, 0);
37 }
38 +
39 +void oidset_parse_file(struct oidset *set, const char *path)
40 +{
41 + FILE *fp;
42 + struct strbuf sb = STRBUF_INIT;
43 + struct object_id oid;
44 +
45 + fp = fopen(path, "r");
46 + if (!fp)
47 + die("could not open object name list: %s", path);
48 + while (!strbuf_getline(&sb, fp)) {
49 + const char *p;
50 + const char *name;
51 +
52 + /*
53 + * Allow trailing comments, leading whitespace
54 + * (including before commits), and empty or whitespace
55 + * only lines.
56 + */
57 + name = strchr(sb.buf, '#');
58 + if (name)
59 + strbuf_setlen(&sb, name - sb.buf);
60 + strbuf_trim(&sb);
61 + if (!sb.len)
62 + continue;
63 +
64 + if (parse_oid_hex(sb.buf, &oid, &p) || *p != '\0')
65 + die("invalid object name: %s", sb.buf);
66 + oidset_insert(set, &oid);
67 + }
68 + if (ferror(fp))
69 + die_errno("Could not read '%s'", path);
70 + fclose(fp);
71 + strbuf_release(&sb);
72 +}
oidset.h
+8
@@ -73,6 +73,14 @@ int oidset_remove(struct oidset *set, const struct object_id *oid);
73 */
74 void oidset_clear(struct oidset *set);
75
76 +/**
77 + * Add the contents of the file 'path' to an initialized oidset. Each line is
78 + * an unabbreviated object name. Comments begin with '#', and trailing comments
79 + * are allowed. Leading whitespace and empty or white-space only lines are
80 + * ignored.
81 + */
82 +void oidset_parse_file(struct oidset *set, const char *path);
83 +
84 struct oidset_iter {
85 kh_oid_t *set;
86 khiter_t iter;