[PATCH v11 06/13] ls-tree: simplify nesting if/else logic in "show_tree()"
- From
Teng Long <dyroneteng@gmail.com>
- Date
- Feb 8, 2022, 12:14 UTC
- Message-ID
- <3816a65fe62b1039c396eb38d27bf2c22e8d84de.1644319434.git.dyroneteng@gmail.com>
- In-Reply-To
- <cover.1644319434.git.dyroneteng@gmail.com>
This commit use "object_type()" to get the type, then remove some of the nested if to let the codes here become more cleaner.
Signed-off-by: Teng Long <dyronetengb@gmail.com> --- builtin/ls-tree.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index ef8c414f61..9c57a36c8c 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -66,19 +66,13 @@ static int show_tree(const struct object_id *oid, struct strbuf *base, { int recurse = 0; size_t baselen; - enum object_type type = OBJ_BLOB; + enum object_type type = object_type(mode); - if (S_ISGITLINK(mode)) { - type = OBJ_COMMIT; - } else if (S_ISDIR(mode)) { - if (show_recursive(base->buf, base->len, pathname)) { - recurse = READ_TREE_RECURSIVE; - if (!(ls_options & LS_SHOW_TREES)) - return recurse; - } - type = OBJ_TREE; - } - else if (ls_options & LS_TREE_ONLY) + if (type == OBJ_TREE && show_recursive(base->buf, base->len, pathname)) + recurse = READ_TREE_RECURSIVE; + if (type == OBJ_TREE && recurse && !(ls_options & LS_SHOW_TREES)) + return recurse; + if (type == OBJ_BLOB && (ls_options & LS_TREE_ONLY)) return 0; if (!(ls_options & LS_NAME_ONLY)) {
-- 2.34.1.403.gb35f2687cf.dirty