ls-tree: simplify nesting if/else logic in "show_tree()"

Use the object_type() function to determine the object type from the "mode" passed to us by read_tree(), instead of doing so with the S_*() macros. Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Teng Long <dyronetengb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Teng Long committed Mar 23, 2022 at 17:13 UTC 87af0ddf5f311e9b6e361daaa7fd591a230261a0
1 file changed +9 -12
builtin/ls-tree.c
+9 -12
@@ -66,20 +66,17 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
66 {
67 int recurse = 0;
68 size_t baselen;
69 - enum object_type type = OBJ_BLOB;
69 + enum object_type type = object_type(mode);
70
71 - if (S_ISGITLINK(mode)) {
72 - type = OBJ_COMMIT;
73 - } else if (S_ISDIR(mode)) {
74 - if (show_recursive(base->buf, base->len, pathname)) {
75 - recurse = READ_TREE_RECURSIVE;
76 - if (!(ls_options & LS_SHOW_TREES))
77 - return recurse;
78 - }
79 - type = OBJ_TREE;
71 + if (type == OBJ_BLOB) {
72 + if (ls_options & LS_TREE_ONLY)
73 + return 0;
74 + } else if (type == OBJ_TREE &&
75 + show_recursive(base->buf, base->len, pathname)) {
76 + recurse = READ_TREE_RECURSIVE;
77 + if (!(ls_options & LS_SHOW_TREES))
78 + return recurse;
79 }
81 - else if (ls_options & LS_TREE_ONLY)
82 - return 0;
80
81 if (!(ls_options & LS_NAME_ONLY)) {
82 if (ls_options & LS_SHOW_SIZE) {