return 0;
}
-static int fsck_cache_tree(struct cache_tree *it)
+static int fsck_cache_tree(struct cache_tree *it, const char *index_path)
{
int i;
int err = 0;
if (verbose)
- fprintf_ln(stderr, _("Checking cache tree"));
+ fprintf_ln(stderr, _("Checking cache tree of %s"), index_path);
if (0 <= it->entry_count) {
struct object *obj = parse_object(the_repository, &it->oid);
if (!obj) {
- error(_("%s: invalid sha1 pointer in cache-tree"),
- oid_to_hex(&it->oid));
+ error(_("%s: invalid sha1 pointer in cache-tree of %s"),
+ oid_to_hex(&it->oid), index_path);
errors_found |= ERROR_REFS;
return 1;
}
err |= objerror(obj, _("non-tree in cache-tree"));
}
for (i = 0; i < it->subtree_nr; i++)
- err |= fsck_cache_tree(it->down[i]->cache_tree);
+ err |= fsck_cache_tree(it->down[i]->cache_tree, index_path);
return err;
}
-static int fsck_resolve_undo(struct index_state *istate)
+static int fsck_resolve_undo(struct index_state *istate,
+ const char *index_path)
{
struct string_list_item *item;
struct string_list *resolve_undo = istate->resolve_undo;
obj = parse_object(the_repository, &ru->oid[i]);
if (!obj) {
- error(_("%s: invalid sha1 pointer in resolve-undo"),
- oid_to_hex(&ru->oid[i]));
+ error(_("%s: invalid sha1 pointer in resolve-undo of %s"),
+ oid_to_hex(&ru->oid[i]),
+ index_path);
errors_found |= ERROR_REFS;
continue;
}
return 0;
}
-static void fsck_index(struct index_state *istate)
+static void fsck_index(struct index_state *istate, const char *index_path,
+ int is_main_index)
{
unsigned int i;
obj = &blob->object;
obj->flags |= USED;
fsck_put_object_name(&fsck_walk_options, &obj->oid,
- ":%s", istate->cache[i]->name);
+ "%s:%s",
+ is_main_index ? "" : index_path,
+ istate->cache[i]->name);
mark_object_reachable(obj);
}
if (istate->cache_tree)
- fsck_cache_tree(istate->cache_tree);
- fsck_resolve_undo(istate);
+ fsck_cache_tree(istate->cache_tree, index_path);
+ fsck_resolve_undo(istate, index_path);
}
static void mark_object_for_connectivity(const struct object_id *oid)
struct worktree *wt = *p;
struct index_state istate =
INDEX_STATE_INIT(the_repository);
+ char *path;
- if (read_index_from(&istate,
- worktree_git_path(wt, "index"),
+ /*
+ * Make a copy since the buffer is reusable
+ * and may get overwritten by other calls
+ * while we're examining the index.
+ */
+ path = xstrdup(worktree_git_path(wt, "index"));
+ if (read_index_from(&istate, path,
get_worktree_git_dir(wt)) > 0)
- fsck_index(&istate);
+ fsck_index(&istate, path, wt->is_current);
discard_index(&istate);
+ free(path);
}
free_worktrees(worktrees);
}