|
1 |
| -#define USE_THE_INDEX_VARIABLE |
2 | 1 | #include "builtin.h"
|
3 | 2 | #include "cache.h"
|
4 | 3 | #include "repository.h"
|
@@ -796,6 +795,35 @@ static int fsck_resolve_undo(struct index_state *istate)
|
796 | 795 | return 0;
|
797 | 796 | }
|
798 | 797 |
|
| 798 | +static void fsck_index(struct index_state *istate) |
| 799 | +{ |
| 800 | + unsigned int i; |
| 801 | + |
| 802 | + /* TODO: audit for interaction with sparse-index. */ |
| 803 | + ensure_full_index(istate); |
| 804 | + for (i = 0; i < istate->cache_nr; i++) { |
| 805 | + unsigned int mode; |
| 806 | + struct blob *blob; |
| 807 | + struct object *obj; |
| 808 | + |
| 809 | + mode = istate->cache[i]->ce_mode; |
| 810 | + if (S_ISGITLINK(mode)) |
| 811 | + continue; |
| 812 | + blob = lookup_blob(the_repository, |
| 813 | + &istate->cache[i]->oid); |
| 814 | + if (!blob) |
| 815 | + continue; |
| 816 | + obj = &blob->object; |
| 817 | + obj->flags |= USED; |
| 818 | + fsck_put_object_name(&fsck_walk_options, &obj->oid, |
| 819 | + ":%s", istate->cache[i]->name); |
| 820 | + mark_object_reachable(obj); |
| 821 | + } |
| 822 | + if (istate->cache_tree) |
| 823 | + fsck_cache_tree(istate->cache_tree); |
| 824 | + fsck_resolve_undo(istate); |
| 825 | +} |
| 826 | + |
799 | 827 | static void mark_object_for_connectivity(const struct object_id *oid)
|
800 | 828 | {
|
801 | 829 | struct object *obj = lookup_unknown_object(the_repository, oid);
|
@@ -959,29 +987,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
|
959 | 987 | verify_index_checksum = 1;
|
960 | 988 | verify_ce_order = 1;
|
961 | 989 | repo_read_index(the_repository);
|
962 |
| - /* TODO: audit for interaction with sparse-index. */ |
963 |
| - ensure_full_index(&the_index); |
964 |
| - for (i = 0; i < the_index.cache_nr; i++) { |
965 |
| - unsigned int mode; |
966 |
| - struct blob *blob; |
967 |
| - struct object *obj; |
968 |
| - |
969 |
| - mode = the_index.cache[i]->ce_mode; |
970 |
| - if (S_ISGITLINK(mode)) |
971 |
| - continue; |
972 |
| - blob = lookup_blob(the_repository, |
973 |
| - &the_index.cache[i]->oid); |
974 |
| - if (!blob) |
975 |
| - continue; |
976 |
| - obj = &blob->object; |
977 |
| - obj->flags |= USED; |
978 |
| - fsck_put_object_name(&fsck_walk_options, &obj->oid, |
979 |
| - ":%s", the_index.cache[i]->name); |
980 |
| - mark_object_reachable(obj); |
981 |
| - } |
982 |
| - if (the_index.cache_tree) |
983 |
| - fsck_cache_tree(the_index.cache_tree); |
984 |
| - fsck_resolve_undo(&the_index); |
| 990 | + fsck_index(the_repository->index); |
985 | 991 | }
|
986 | 992 |
|
987 | 993 | check_connectivity();
|
|
0 commit comments