mirror of
https://github.com/git/git
synced 2024-10-04 15:49:47 +00:00
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>
This commit is contained in:
parent
77556354bb
commit
24eb33ebc5
18
fsck.c
18
fsck.c
|
@ -181,7 +181,7 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,
|
||||||
return msg_type;
|
return msg_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_skiplist(struct fsck_options *options, const char *path)
|
void oidset_parse_file(struct oidset *set, const char *path)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
|
@ -189,26 +189,26 @@ static void init_skiplist(struct fsck_options *options, const char *path)
|
||||||
|
|
||||||
fp = fopen(path, "r");
|
fp = fopen(path, "r");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
die("Could not open skip list: %s", path);
|
die("could not open object name list: %s", path);
|
||||||
while (!strbuf_getline(&sb, fp)) {
|
while (!strbuf_getline(&sb, fp)) {
|
||||||
const char *p;
|
const char *p;
|
||||||
const char *hash;
|
const char *name;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allow trailing comments, leading whitespace
|
* Allow trailing comments, leading whitespace
|
||||||
* (including before commits), and empty or whitespace
|
* (including before commits), and empty or whitespace
|
||||||
* only lines.
|
* only lines.
|
||||||
*/
|
*/
|
||||||
hash = strchr(sb.buf, '#');
|
name = strchr(sb.buf, '#');
|
||||||
if (hash)
|
if (name)
|
||||||
strbuf_setlen(&sb, hash - sb.buf);
|
strbuf_setlen(&sb, name - sb.buf);
|
||||||
strbuf_trim(&sb);
|
strbuf_trim(&sb);
|
||||||
if (!sb.len)
|
if (!sb.len)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (parse_oid_hex(sb.buf, &oid, &p) || *p != '\0')
|
if (parse_oid_hex(sb.buf, &oid, &p) || *p != '\0')
|
||||||
die("Invalid SHA-1: %s", sb.buf);
|
die("invalid object name: %s", sb.buf);
|
||||||
oidset_insert(&options->skiplist, &oid);
|
oidset_insert(set, &oid);
|
||||||
}
|
}
|
||||||
if (ferror(fp))
|
if (ferror(fp))
|
||||||
die_errno("Could not read '%s'", path);
|
die_errno("Could not read '%s'", path);
|
||||||
|
@ -284,7 +284,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
|
||||||
if (!strcmp(buf, "skiplist")) {
|
if (!strcmp(buf, "skiplist")) {
|
||||||
if (equal == len)
|
if (equal == len)
|
||||||
die("skiplist requires a path");
|
die("skiplist requires a path");
|
||||||
init_skiplist(options, buf + equal + 1);
|
oidset_parse_file(&options->skiplist, buf + equal + 1);
|
||||||
buf += len + 1;
|
buf += len + 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,9 +164,9 @@ test_expect_success 'fsck with unsorted skipList' '
|
||||||
test_expect_success 'fsck with invalid or bogus skipList input' '
|
test_expect_success 'fsck with invalid or bogus skipList input' '
|
||||||
git -c fsck.skipList=/dev/null -c fsck.missingEmail=ignore fsck &&
|
git -c fsck.skipList=/dev/null -c fsck.missingEmail=ignore fsck &&
|
||||||
test_must_fail git -c fsck.skipList=does-not-exist -c fsck.missingEmail=ignore fsck 2>err &&
|
test_must_fail git -c fsck.skipList=does-not-exist -c fsck.missingEmail=ignore fsck 2>err &&
|
||||||
test_i18ngrep "Could not open skip list: does-not-exist" err &&
|
test_i18ngrep "could not open.*: does-not-exist" err &&
|
||||||
test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err &&
|
test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err &&
|
||||||
test_i18ngrep "Invalid SHA-1: \[core\]" err
|
test_i18ngrep "invalid object name: \[core\]" err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'fsck with other accepted skipList input (comments & empty lines)' '
|
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'
|
||||||
test_expect_success 'fsck with invalid abbreviated skipList input' '
|
test_expect_success 'fsck with invalid abbreviated skipList input' '
|
||||||
echo $commit | test_copy_bytes 20 >SKIP.abbreviated &&
|
echo $commit | test_copy_bytes 20 >SKIP.abbreviated &&
|
||||||
test_must_fail git -c fsck.skipList=SKIP.abbreviated fsck 2>err-abbreviated &&
|
test_must_fail git -c fsck.skipList=SKIP.abbreviated fsck 2>err-abbreviated &&
|
||||||
test_i18ngrep "^fatal: Invalid SHA-1: " err-abbreviated
|
test_i18ngrep "^fatal: invalid object name: " err-abbreviated
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'fsck with exhaustive accepted skipList input (various types of comments etc.)' '
|
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' '
|
||||||
test_must_fail git push --porcelain dst bogus &&
|
test_must_fail git push --porcelain dst bogus &&
|
||||||
git --git-dir=dst/.git config receive.fsck.skipList does-not-exist &&
|
git --git-dir=dst/.git config receive.fsck.skipList does-not-exist &&
|
||||||
test_must_fail git push --porcelain dst bogus 2>err &&
|
test_must_fail git push --porcelain dst bogus 2>err &&
|
||||||
test_i18ngrep "Could not open skip list: does-not-exist" err &&
|
test_i18ngrep "could not open.*: does-not-exist" err &&
|
||||||
git --git-dir=dst/.git config receive.fsck.skipList config &&
|
git --git-dir=dst/.git config receive.fsck.skipList config &&
|
||||||
test_must_fail git push --porcelain dst bogus 2>err &&
|
test_must_fail git push --porcelain dst bogus 2>err &&
|
||||||
test_i18ngrep "Invalid SHA-1: \[core\]" err &&
|
test_i18ngrep "invalid object name: \[core\]" err &&
|
||||||
|
|
||||||
git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
|
git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
|
||||||
git push --porcelain dst bogus
|
git push --porcelain dst bogus
|
||||||
|
@ -255,10 +255,10 @@ test_expect_success 'fetch with fetch.fsck.skipList' '
|
||||||
test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
|
test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
|
||||||
git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist &&
|
git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist &&
|
||||||
test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
|
test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
|
||||||
test_i18ngrep "Could not open skip list: does-not-exist" err &&
|
test_i18ngrep "could not open.*: does-not-exist" err &&
|
||||||
git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/config &&
|
git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/config &&
|
||||||
test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
|
test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
|
||||||
test_i18ngrep "Invalid SHA-1: \[core\]" err &&
|
test_i18ngrep "invalid object name: \[core\]" err &&
|
||||||
|
|
||||||
git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP &&
|
git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP &&
|
||||||
git --git-dir=dst/.git fetch "file://$(pwd)" $refspec
|
git --git-dir=dst/.git fetch "file://$(pwd)" $refspec
|
||||||
|
|
Loading…
Reference in a new issue