Skip to content

Commit 3486d8d

Browse files
Barret Rhodengitster
authored andcommitted
Move init_skiplist() outside of fsck
init_skiplist() took a file consisting of SHA-1s and comments and added the objects to an oidset. This functionality is useful for other commands. Signed-off-by: Barret Rhoden <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7755635 commit 3486d8d

File tree

4 files changed

+51
-43
lines changed

4 files changed

+51
-43
lines changed

fsck.c

Lines changed: 1 addition & 36 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-
static void init_skiplist(struct fsck_options *options, 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 skip list: %s", path);
193-
while (!strbuf_getline(&sb, fp)) {
194-
const char *p;
195-
const char *hash;
196-
197-
/*
198-
* Allow trailing comments, leading whitespace
199-
* (including before commits), and empty or whitespace
200-
* only lines.
201-
*/
202-
hash = strchr(sb.buf, '#');
203-
if (hash)
204-
strbuf_setlen(&sb, hash - 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 SHA-1: %s", sb.buf);
211-
oidset_insert(&options->skiplist, &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"))
@@ -284,7 +249,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
284249
if (!strcmp(buf, "skiplist")) {
285250
if (equal == len)
286251
die("skiplist requires a path");
287-
init_skiplist(options, buf + equal + 1);
252+
oidset_parse_file(&options->skiplist, buf + equal + 1);
288253
buf += len + 1;
289254
continue;
290255
}

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;

t/t5504-fetch-receive-strict.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ test_expect_success 'fsck with unsorted skipList' '
164164
test_expect_success 'fsck with invalid or bogus skipList input' '
165165
git -c fsck.skipList=/dev/null -c fsck.missingEmail=ignore fsck &&
166166
test_must_fail git -c fsck.skipList=does-not-exist -c fsck.missingEmail=ignore fsck 2>err &&
167-
test_i18ngrep "Could not open skip list: does-not-exist" err &&
167+
test_i18ngrep "Could not open object name list: does-not-exist" err &&
168168
test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err &&
169-
test_i18ngrep "Invalid SHA-1: \[core\]" err
169+
test_i18ngrep "Invalid object name: \[core\]" err
170170
'
171171

172172
test_expect_success 'fsck with other accepted skipList input (comments & empty lines)' '
@@ -193,7 +193,7 @@ test_expect_success 'fsck no garbage output from comments & empty lines errors'
193193
test_expect_success 'fsck with invalid abbreviated skipList input' '
194194
echo $commit | test_copy_bytes 20 >SKIP.abbreviated &&
195195
test_must_fail git -c fsck.skipList=SKIP.abbreviated fsck 2>err-abbreviated &&
196-
test_i18ngrep "^fatal: Invalid SHA-1: " err-abbreviated
196+
test_i18ngrep "^fatal: Invalid object name: " err-abbreviated
197197
'
198198

199199
test_expect_success 'fsck with exhaustive accepted skipList input (various types of comments etc.)' '
@@ -226,10 +226,10 @@ test_expect_success 'push with receive.fsck.skipList' '
226226
test_must_fail git push --porcelain dst bogus &&
227227
git --git-dir=dst/.git config receive.fsck.skipList does-not-exist &&
228228
test_must_fail git push --porcelain dst bogus 2>err &&
229-
test_i18ngrep "Could not open skip list: does-not-exist" err &&
229+
test_i18ngrep "Could not open object name list: does-not-exist" err &&
230230
git --git-dir=dst/.git config receive.fsck.skipList config &&
231231
test_must_fail git push --porcelain dst bogus 2>err &&
232-
test_i18ngrep "Invalid SHA-1: \[core\]" err &&
232+
test_i18ngrep "Invalid object name: \[core\]" err &&
233233
234234
git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
235235
git push --porcelain dst bogus
@@ -255,10 +255,10 @@ test_expect_success 'fetch with fetch.fsck.skipList' '
255255
test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
256256
git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist &&
257257
test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
258-
test_i18ngrep "Could not open skip list: does-not-exist" err &&
258+
test_i18ngrep "Could not open object name list: does-not-exist" err &&
259259
git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/config &&
260260
test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
261-
test_i18ngrep "Invalid SHA-1: \[core\]" err &&
261+
test_i18ngrep "Invalid object name: \[core\]" err &&
262262
263263
git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP &&
264264
git --git-dir=dst/.git fetch "file://$(pwd)" $refspec

0 commit comments

Comments
 (0)