Skip to content

Commit aac2abe

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ae24b03 commit aac2abe

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

builtin/cat-file.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
109109
unsigned long size;
110110
struct object_context obj_context = {0};
111111
struct object_info oi = OBJECT_INFO_INIT;
112-
struct strbuf sb = STRBUF_INIT;
113112
unsigned flags = OBJECT_INFO_LOOKUP_REPLACE;
114113
unsigned get_oid_flags =
115114
GET_OID_RECORD_PATH |
@@ -132,16 +131,12 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
132131
buf = NULL;
133132
switch (opt) {
134133
case 't':
135-
oi.type_name = &sb;
134+
oi.typep = &type;
136135
if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
137136
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;
145140

146141
case 's':
147142
oi.sizep = &size;

0 commit comments

Comments
 (0)