|
10 | 10 | #include "utf8.h"
|
11 | 11 | #include "sha1-array.h"
|
12 | 12 | #include "decorate.h"
|
| 13 | +#include "oidset.h" |
| 14 | + |
| 15 | +static struct oidset gitmodules_found = OIDSET_INIT; |
| 16 | +static struct oidset gitmodules_done = OIDSET_INIT; |
13 | 17 |
|
14 | 18 | #define FSCK_FATAL -1
|
15 | 19 | #define FSCK_INFO -2
|
|
44 | 48 | FUNC(MISSING_TAG_ENTRY, ERROR) \
|
45 | 49 | FUNC(MISSING_TAG_OBJECT, ERROR) \
|
46 | 50 | FUNC(MISSING_TREE, ERROR) \
|
| 51 | + FUNC(MISSING_TREE_OBJECT, ERROR) \ |
47 | 52 | FUNC(MISSING_TYPE, ERROR) \
|
48 | 53 | FUNC(MISSING_TYPE_ENTRY, ERROR) \
|
49 | 54 | FUNC(MULTIPLE_AUTHORS, ERROR) \
|
50 | 55 | FUNC(TAG_OBJECT_NOT_TAG, ERROR) \
|
51 | 56 | FUNC(TREE_NOT_SORTED, ERROR) \
|
52 | 57 | FUNC(UNKNOWN_TYPE, ERROR) \
|
53 | 58 | FUNC(ZERO_PADDED_DATE, ERROR) \
|
| 59 | + FUNC(GITMODULES_MISSING, ERROR) \ |
| 60 | + FUNC(GITMODULES_BLOB, ERROR) \ |
54 | 61 | /* warnings */ \
|
55 | 62 | FUNC(BAD_FILEMODE, WARN) \
|
56 | 63 | FUNC(EMPTY_NAME, WARN) \
|
@@ -563,6 +570,10 @@ static int fsck_tree(struct tree *item, struct fsck_options *options)
|
563 | 570 | has_dotdot |= !strcmp(name, "..");
|
564 | 571 | has_dotgit |= is_hfs_dotgit(name) || is_ntfs_dotgit(name);
|
565 | 572 | has_zero_pad |= *(char *)desc.buffer == '0';
|
| 573 | + |
| 574 | + if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) |
| 575 | + oidset_insert(&gitmodules_found, oid); |
| 576 | + |
566 | 577 | if (update_tree_entry_gently(&desc)) {
|
567 | 578 | retval += report(options, &item->object, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree");
|
568 | 579 | break;
|
@@ -936,3 +947,50 @@ int fsck_error_function(struct fsck_options *o,
|
936 | 947 | error("object %s: %s", describe_object(o, obj), message);
|
937 | 948 | return 1;
|
938 | 949 | }
|
| 950 | + |
| 951 | +int fsck_finish(struct fsck_options *options) |
| 952 | +{ |
| 953 | + int ret = 0; |
| 954 | + struct oidset_iter iter; |
| 955 | + const struct object_id *oid; |
| 956 | + |
| 957 | + oidset_iter_init(&gitmodules_found, &iter); |
| 958 | + while ((oid = oidset_iter_next(&iter))) { |
| 959 | + struct blob *blob; |
| 960 | + enum object_type type; |
| 961 | + unsigned long size; |
| 962 | + char *buf; |
| 963 | + |
| 964 | + if (oidset_contains(&gitmodules_done, oid)) |
| 965 | + continue; |
| 966 | + |
| 967 | + blob = lookup_blob(oid); |
| 968 | + if (!blob) { |
| 969 | + ret |= report(options, &blob->object, |
| 970 | + FSCK_MSG_GITMODULES_BLOB, |
| 971 | + "non-blob found at .gitmodules"); |
| 972 | + continue; |
| 973 | + } |
| 974 | + |
| 975 | + buf = read_sha1_file(oid->hash, &type, &size); |
| 976 | + if (!buf) { |
| 977 | + ret |= report(options, &blob->object, |
| 978 | + FSCK_MSG_GITMODULES_MISSING, |
| 979 | + "unable to read .gitmodules blob"); |
| 980 | + continue; |
| 981 | + } |
| 982 | + |
| 983 | + if (type == OBJ_BLOB) |
| 984 | + ret |= fsck_blob(blob, buf, size, options); |
| 985 | + else |
| 986 | + ret |= report(options, &blob->object, |
| 987 | + FSCK_MSG_GITMODULES_BLOB, |
| 988 | + "non-blob found at .gitmodules"); |
| 989 | + free(buf); |
| 990 | + } |
| 991 | + |
| 992 | + |
| 993 | + oidset_clear(&gitmodules_found); |
| 994 | + oidset_clear(&gitmodules_done); |
| 995 | + return ret; |
| 996 | +} |
0 commit comments