fsck: use oids rather than objects for object_name API

We don't actually care about having object structs; we only need to look
up decorations by oid. Let's accept this more limited form, which will
give our callers more flexibility.

Note that the decoration API we rely on uses object structs itself (even
though it only looks at their oids). We can solve this by switching to
a kh_oid_map (we could also use the hashmap oidmap, but it's more
awkward for the simple case of just storing a void pointer).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King
2019-10-18 00:57:37 -04:00
committed by Junio C Hamano
parent d40bbc109b
commit 733902905d
3 changed files with 45 additions and 37 deletions

View File

@ -52,7 +52,7 @@ static int name_objects;
static const char *describe_object(struct object *obj)
{
return fsck_describe_object(&fsck_walk_options, obj);
return fsck_describe_object(&fsck_walk_options, &obj->oid);
}
static const char *printable_type(struct object *obj)
@ -483,7 +483,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
obj = lookup_object(the_repository, oid);
if (obj && (obj->flags & HAS_OBJ)) {
if (timestamp)
fsck_put_object_name(&fsck_walk_options, obj,
fsck_put_object_name(&fsck_walk_options, oid,
"%s@{%"PRItime"}",
refname, timestamp);
obj->flags |= USED;
@ -550,7 +550,7 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
default_refs++;
obj->flags |= USED;
fsck_put_object_name(&fsck_walk_options,
obj, "%s", refname);
oid, "%s", refname);
mark_object_reachable(obj);
return 0;
@ -724,7 +724,7 @@ static int fsck_cache_tree(struct cache_tree *it)
return 1;
}
obj->flags |= USED;
fsck_put_object_name(&fsck_walk_options, obj, ":");
fsck_put_object_name(&fsck_walk_options, &it->oid, ":");
mark_object_reachable(obj);
if (obj->type != OBJ_TREE)
err |= objerror(obj, _("non-tree in cache-tree"));
@ -869,7 +869,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
}
obj->flags |= USED;
fsck_put_object_name(&fsck_walk_options, obj,
fsck_put_object_name(&fsck_walk_options, &oid,
"%s", arg);
mark_object_reachable(obj);
continue;
@ -906,7 +906,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
continue;
obj = &blob->object;
obj->flags |= USED;
fsck_put_object_name(&fsck_walk_options, obj,
fsck_put_object_name(&fsck_walk_options, &obj->oid,
":%s", active_cache[i]->name);
mark_object_reachable(obj);
}