fsck: rename and touch up init_skiplist()
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 and will be moved to oidset.c in a future commit. In preparation for that move, this commit renames it to oidset_parse_file() to reflect its more generic usage and cleans up a few of the names. 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
24eb33ebc515fe0f459a3fed6b16614a0312037f
2 files changed
+16
-16
fsck.c
+9
-9
@@ -181,7 +181,7 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,
181
return msg_type;
182
}
183
184
-static void init_skiplist(struct fsck_options *options, const char *path)
184
+void oidset_parse_file(struct oidset *set, const char *path)
185
{
186
FILE *fp;
187
struct strbuf sb = STRBUF_INIT;
@@ -189,26 +189,26 @@ static void init_skiplist(struct fsck_options *options, const char *path)
189
190
fp = fopen(path, "r");
191
if (!fp)
192
- die("Could not open skip list: %s", path);
192
+ die("could not open object name list: %s", path);
193
while (!strbuf_getline(&sb, fp)) {
194
const char *p;
195
- const char *hash;
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
- hash = strchr(sb.buf, '#');
203
- if (hash)
204
- strbuf_setlen(&sb, hash - sb.buf);
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 SHA-1: %s", sb.buf);
211
- oidset_insert(&options->skiplist, &oid);
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);
@@ -284,7 +284,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
284
if (!strcmp(buf, "skiplist")) {
285
if (equal == len)
286
die("skiplist requires a path");
287
- init_skiplist(options, buf + equal + 1);
287
+ oidset_parse_file(&options->skiplist, buf + equal + 1);
288
buf += len + 1;
289
continue;
290
}
t/t5504-fetch-receive-strict.sh
+7
-7
@@ -164,9 +164,9 @@ test_expect_success 'fsck with unsorted skipList' '
164
test_expect_success 'fsck with invalid or bogus skipList input' '
165
git -c fsck.skipList=/dev/null -c fsck.missingEmail=ignore fsck &&
166
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.*: does-not-exist" err &&
168
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
170
'
171
172
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'
193
test_expect_success 'fsck with invalid abbreviated skipList input' '
194
echo $commit | test_copy_bytes 20 >SKIP.abbreviated &&
195
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
197
'
198
199
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' '
226
test_must_fail git push --porcelain dst bogus &&
227
git --git-dir=dst/.git config receive.fsck.skipList does-not-exist &&
228
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.*: does-not-exist" err &&
230
git --git-dir=dst/.git config receive.fsck.skipList config &&
231
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 &&
233
234
git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
235
git push --porcelain dst bogus
@@ -255,10 +255,10 @@ test_expect_success 'fetch with fetch.fsck.skipList' '
255
test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
256
git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist &&
257
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.*: does-not-exist" err &&
259
git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/config &&
260
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 &&
262
263
git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP &&
264
git --git-dir=dst/.git fetch "file://$(pwd)" $refspec