summaryrefslogtreecommitdiff
path: root/builtin/ls-tree.c
diff options
context:
space:
mode:
authorTeng Long <dyroneteng@gmail.com>2022-03-23 09:13:07 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-03-23 18:38:39 (GMT)
commit87af0ddf5f311e9b6e361daaa7fd591a230261a0 (patch)
tree1112af4f653ad1b2b3841ee36a6088d81217d36c /builtin/ls-tree.c
parent889f78383eb1e93663ad38a231607e04a1593713 (diff)
downloadgit-87af0ddf5f311e9b6e361daaa7fd591a230261a0.zip
git-87af0ddf5f311e9b6e361daaa7fd591a230261a0.tar.gz
git-87af0ddf5f311e9b6e361daaa7fd591a230261a0.tar.bz2
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>
Diffstat (limited to 'builtin/ls-tree.c')
-rw-r--r--builtin/ls-tree.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index ef8c414..d4be71b 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -66,20 +66,17 @@ 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;
+ if (type == OBJ_BLOB) {
+ if (ls_options & LS_TREE_ONLY)
+ return 0;
+ } else if (type == OBJ_TREE &&
+ show_recursive(base->buf, base->len, pathname)) {
+ recurse = READ_TREE_RECURSIVE;
+ if (!(ls_options & LS_SHOW_TREES))
+ return recurse;
}
- else if (ls_options & LS_TREE_ONLY)
- return 0;
if (!(ls_options & LS_NAME_ONLY)) {
if (ls_options & LS_SHOW_SIZE) {