cat-file: use type enum instead of buffer for -t option

Now that we no longer support OBJECT_INFO_ALLOW_UNKNOWN_TYPE, there is no need to pass a strbuf into oid_object_info_extended() to record the type. The regular object_type enum is sufficient to capture all of the types we will allow. This simplifies the code a bit, and will eventually let us drop object_info's type_name strbuf support. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 16, 2025 at 00:49 UTC aac2abeca7077aa5f87f4132b98d37dd938b3573
1 file changed +4 -9
builtin/cat-file.c
+4 -9
@@ -109,7 +109,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
109 unsigned long size;
110 struct object_context obj_context = {0};
111 struct object_info oi = OBJECT_INFO_INIT;
112 - struct strbuf sb = STRBUF_INIT;
112 unsigned flags = OBJECT_INFO_LOOKUP_REPLACE;
113 unsigned get_oid_flags =
114 GET_OID_RECORD_PATH |
@@ -132,16 +131,12 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
131 buf = NULL;
132 switch (opt) {
133 case 't':
135 - oi.type_name = &sb;
134 + oi.typep = &type;
135 if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
136 die("git cat-file: could not get object info");
138 - if (sb.len) {
139 - printf("%s\n", sb.buf);
140 - strbuf_release(&sb);
141 - ret = 0;
142 - goto cleanup;
143 - }
144 - break;
137 + printf("%s\n", type_name(type));
138 + ret = 0;
139 + goto cleanup;
140
141 case 's':
142 oi.sizep = &size;