Skip to content

Commit 87af0dd

Browse files
dyronegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Teng Long <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 889f783 commit 87af0dd

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

builtin/ls-tree.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,17 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
6666
{
6767
int recurse = 0;
6868
size_t baselen;
69-
enum object_type type = OBJ_BLOB;
69+
enum object_type type = object_type(mode);
7070

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;
8079
}
81-
else if (ls_options & LS_TREE_ONLY)
82-
return 0;
8380

8481
if (!(ls_options & LS_NAME_ONLY)) {
8582
if (ls_options & LS_SHOW_SIZE) {

0 commit comments

Comments
 (0)