On Thu, Jan 13 2022, Teng Long wrote: Re the $subject: Is "optimize naming" here just referring to the s/retval/recurse/g? Personally I think just a s/retval/ret/g here would make more senes if we're doing any change at all, and in either case having this variable re-rename split up as its own commit would make the proposed control flow changes clearer. > The variable which "show_tree()" return is named "retval", a name that's > a little hard to understand. This commit tries to make the variable > and the related codes more clear in the context. > > The commit firstly rename "retval" to "recurse" which is a more > meaningful name than before. Secondly, "get_type()" is introduced > to setup the "type" by "mode", this will remove some of the nested if. > After this, The codes here become a little bit clearer, so we do not > need to take a look at "read_tree_at()" in "tree.c" to make sure the > context of the return value. > > Signed-off-by: Teng Long <dyronetengb@xxxxxxxxx> > --- > builtin/ls-tree.c | 33 ++++++++++++++++++--------------- > 1 file changed, 18 insertions(+), 15 deletions(-) > > diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c > index eecc7482d5..9729854a3d 100644 > --- a/builtin/ls-tree.c > +++ b/builtin/ls-tree.c > @@ -61,24 +61,27 @@ static int show_recursive(const char *base, size_t baselen, const char *pathname > return 0; > } > > +static enum object_type get_type(unsigned int mode) > +{ > + return (S_ISGITLINK(mode) > + ? OBJ_COMMIT > + : S_ISDIR(mode) > + ? OBJ_TREE > + : OBJ_BLOB); > +} This new function is a re-invention of the object_type() utility in cache.h, and isn't needed. I.e.... > static int show_tree(const struct object_id *oid, struct strbuf *base, > const char *pathname, unsigned mode, void *context) > { > - int retval = 0; > + int recurse = 0; > size_t baselen; > - enum object_type type = OBJ_BLOB; > - > - if (S_ISGITLINK(mode)) { > - type = OBJ_COMMIT; > - } else if (S_ISDIR(mode)) { > - if (show_recursive(base->buf, base->len, pathname)) { > - retval = READ_TREE_RECURSIVE; > - if (!(ls_options & LS_SHOW_TREES)) > - return retval; > - } > - type = OBJ_TREE; > - } > - else if (ls_options & LS_TREE_ONLY) > + enum object_type type = get_type(mode); ...just drop it and do this: - enum object_type type = get_type(mode); + enum object_type type = object_type(mode);