object.h: add lookup_object_by_type() function
commit7463064b28086c0a765e247bc8336f8e32356494
authorJeff King <peff@peff.net>
Tue, 22 Jun 2021 16:06:41 +0000 (22 12:06 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 29 Jun 2021 03:30:18 +0000 (28 20:30 -0700)
tree1d55d80344db95b9876e80537022563166ffb8a1
parent542d6abbb4e838cf1c47612a2b4b33f2a31e6277
object.h: add lookup_object_by_type() function

In some cases it's useful for efficiency reasons to get the type of an
object before deciding whether to parse it, but we still want an object
struct. E.g., in reachable.c, bitmaps give us the type, but we just want
to mark flags on each object. Likewise, we may loop over every object
and only parse tags in order to peel them; checking the type first lets
us avoid parsing the non-tags.

But our lookup_blob(), etc, functions make getting an object struct
annoying: we have to call the right function for every type. And we
cannot just use the generic lookup_object(), because it only returns an
already-seen object; it won't allocate a new object struct.

Let's provide a function that dispatches to the correct lookup_*
function based on a run-time type. In fact, reachable.c already has such
a helper, so we'll just make that public.

I did change the return type from "void *" to "struct object *". While
the former is a clever way to avoid casting inside the function, it's
less safe and less informative to people reading the function
declaration.

The next commit will add a new caller.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object.c
object.h
reachable.c