731
return 0;
732
}
733
734
-static int fsck_cache_tree(struct cache_tree *it)
734
+static int fsck_cache_tree(struct cache_tree *it, const char *index_path)
735
{
736
int i;
737
int err = 0;
738
739
if (verbose)
740
- fprintf_ln(stderr, _("Checking cache tree"));
740
+ fprintf_ln(stderr, _("Checking cache tree of %s"), index_path);
741
742
if (0 <= it->entry_count) {
743
struct object *obj = parse_object(the_repository, &it->oid);
744
if (!obj) {
745
- error(_("%s: invalid sha1 pointer in cache-tree"),
746
- oid_to_hex(&it->oid));
745
+ error(_("%s: invalid sha1 pointer in cache-tree of %s"),
746
+ oid_to_hex(&it->oid), index_path);
747
errors_found |= ERROR_REFS;
748
return 1;
749
}
754
err |= objerror(obj, _("non-tree in cache-tree"));
755
}
756
for (i = 0; i < it->subtree_nr; i++)
757
- err |= fsck_cache_tree(it->down[i]->cache_tree);
757
+ err |= fsck_cache_tree(it->down[i]->cache_tree, index_path);
758
return err;
759
}
760
761
-static int fsck_resolve_undo(struct index_state *istate)
761
+static int fsck_resolve_undo(struct index_state *istate,
762
+ const char *index_path)
763
{
764
struct string_list_item *item;
765
struct string_list *resolve_undo = istate->resolve_undo;
782
783
obj = parse_object(the_repository, &ru->oid[i]);
784
if (!obj) {
784
- error(_("%s: invalid sha1 pointer in resolve-undo"),
785
- oid_to_hex(&ru->oid[i]));
785
+ error(_("%s: invalid sha1 pointer in resolve-undo of %s"),
786
+ oid_to_hex(&ru->oid[i]),
787
+ index_path);
788
errors_found |= ERROR_REFS;
789
continue;
790
}
797
return 0;
798
}
799
798
-static void fsck_index(struct index_state *istate)
800
+static void fsck_index(struct index_state *istate, const char *index_path,
801
+ int is_main_index)
802
{
803
unsigned int i;
804
819
obj = &blob->object;
820
obj->flags |= USED;
821
fsck_put_object_name(&fsck_walk_options, &obj->oid,
819
- ":%s", istate->cache[i]->name);
822
+ "%s:%s",
823
+ is_main_index ? "" : index_path,
824
+ istate->cache[i]->name);
825
mark_object_reachable(obj);
826
}
827
if (istate->cache_tree)
823
- fsck_cache_tree(istate->cache_tree);
824
- fsck_resolve_undo(istate);
828
+ fsck_cache_tree(istate->cache_tree, index_path);
829
+ fsck_resolve_undo(istate, index_path);
830
}
831
832
static void mark_object_for_connectivity(const struct object_id *oid)
999
struct worktree *wt = *p;
1000
struct index_state istate =
1001
INDEX_STATE_INIT(the_repository);
1002
+ char *path;
1003
998
- if (read_index_from(&istate,
999
- worktree_git_path(wt, "index"),
1004
+ /*
1005
+ * Make a copy since the buffer is reusable
1006
+ * and may get overwritten by other calls
1007
+ * while we're examining the index.
1008
+ */
1009
+ path = xstrdup(worktree_git_path(wt, "index"));
1010
+ if (read_index_from(&istate, path,
1011
get_worktree_git_dir(wt)) > 0)
1001
- fsck_index(&istate);
1012
+ fsck_index(&istate, path, wt->is_current);
1013
discard_index(&istate);
1014
+ free(path);
1015
}
1016
free_worktrees(worktrees);
1017
}