ls-tree: use "enum object_type", not {blob,tree,commit}_type

Change the ls-tree.c code to use type_name() on the enum instead of using the string constants. This doesn't matter either way for performance, but makes this a bit easier to read as we'll no longer need a strcmp() here. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Mar 23, 2022 at 17:13 UTC 26f6d4d5a015ae95b0818140b6edf297e78e4e67
1 file changed +6 -6
builtin/ls-tree.c
+6 -6
@@ -66,17 +66,17 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
66 {
67 int retval = 0;
68 int baselen;
69 - const char *type = blob_type;
69 + enum object_type type = OBJ_BLOB;
70
71 if (S_ISGITLINK(mode)) {
72 - type = commit_type;
72 + type = OBJ_COMMIT;
73 } else if (S_ISDIR(mode)) {
74 if (show_recursive(base->buf, base->len, pathname)) {
75 retval = READ_TREE_RECURSIVE;
76 if (!(ls_options & LS_SHOW_TREES))
77 return retval;
78 }
79 - type = tree_type;
79 + type = OBJ_TREE;
80 }
81 else if (ls_options & LS_TREE_ONLY)
82 return 0;
@@ -84,7 +84,7 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
84 if (!(ls_options & LS_NAME_ONLY)) {
85 if (ls_options & LS_SHOW_SIZE) {
86 char size_text[24];
87 - if (!strcmp(type, blob_type)) {
87 + if (type == OBJ_BLOB) {
88 unsigned long size;
89 if (oid_object_info(the_repository, oid, &size) == OBJ_BAD)
90 xsnprintf(size_text, sizeof(size_text),
@@ -95,11 +95,11 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
95 } else {
96 xsnprintf(size_text, sizeof(size_text), "-");
97 }
98 - printf("%06o %s %s %7s\t", mode, type,
98 + printf("%06o %s %s %7s\t", mode, type_name(type),
99 find_unique_abbrev(oid, abbrev),
100 size_text);
101 } else {
102 - printf("%06o %s %s\t", mode, type,
102 + printf("%06o %s %s\t", mode, type_name(type),
103 find_unique_abbrev(oid, abbrev));
104 }
105 }