Skip to content

Commit f93895f

Browse files
Barret Rhodengitster
authored andcommitted
Move oidset_parse_file() to oidset.c
Signed-off-by: Barret Rhoden <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 24eb33e commit f93895f

File tree

3 files changed

+43
-35
lines changed

3 files changed

+43
-35
lines changed

fsck.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -181,41 +181,6 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,
181181
return msg_type;
182182
}
183183

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-
219184
static int parse_msg_type(const char *str)
220185
{
221186
if (!strcmp(str, "error"))

oidset.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,38 @@ void oidset_clear(struct oidset *set)
3535
kh_release_oid(&set->set);
3636
oidset_init(set, 0);
3737
}
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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ int oidset_remove(struct oidset *set, const struct object_id *oid);
7373
*/
7474
void oidset_clear(struct oidset *set);
7575

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+
7684
struct oidset_iter {
7785
kh_oid_t *set;
7886
khiter_t iter;

0 commit comments

Comments
 (0)