Skip to content

Commit 8840069

Browse files
peffgitster
authored andcommitted
fsck: factor out index fsck
The code to fsck an index operates directly on the_index. Let's move it into its own function in preparation for handling the index files from other worktrees. Since we now have only a single reference to the_index, let's drop our USE_THE_INDEX_VARIABLE definition and just use the_repository.index directly. That's a minor cleanup, but also ensures that we didn't miss any references when moving the code into fsck_index(). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 768bb23 commit 8840069

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

builtin/fsck.c

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_INDEX_VARIABLE
21
#include "builtin.h"
32
#include "cache.h"
43
#include "repository.h"
@@ -796,6 +795,35 @@ static int fsck_resolve_undo(struct index_state *istate)
796795
return 0;
797796
}
798797

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+
799827
static void mark_object_for_connectivity(const struct object_id *oid)
800828
{
801829
struct object *obj = lookup_unknown_object(the_repository, oid);
@@ -959,29 +987,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
959987
verify_index_checksum = 1;
960988
verify_ce_order = 1;
961989
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);
985991
}
986992

987993
check_connectivity();

0 commit comments

Comments
 (0)