]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ls-files: don't needlessly pass around stage variable
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Sat, 20 Mar 2021 22:37:47 +0000 (23:37 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 20 Mar 2021 23:09:26 +0000 (16:09 -0700)
Now that read_tree() has been moved to ls-files.c we can get rid of
the stage != 1 case that'll never happen.

Let's not use read_tree_recursive() as a pass-through to pass "stage =
1" either. For now we'll pass an unused "stage = 0" for consistency
with other read_tree_recursive() callers, that argument will be
removed in a follow-up commit.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/ls-files.c

index a44586228137e14ac2c878376bf853c63492810f..3149a2769a394474592fa70063a45be527f89f08 100644 (file)
@@ -425,7 +425,7 @@ static int read_one_entry_opt(struct index_state *istate,
                              const struct object_id *oid,
                              const char *base, int baselen,
                              const char *pathname,
-                             unsigned mode, int stage, int opt)
+                             unsigned mode, int opt)
 {
        int len;
        struct cache_entry *ce;
@@ -437,7 +437,7 @@ static int read_one_entry_opt(struct index_state *istate,
        ce = make_empty_cache_entry(istate, baselen + len);
 
        ce->ce_mode = create_ce_mode(mode);
-       ce->ce_flags = create_ce_flags(stage);
+       ce->ce_flags = create_ce_flags(1);
        ce->ce_namelen = baselen + len;
        memcpy(ce->name, base, baselen);
        memcpy(ce->name + baselen, pathname, len+1);
@@ -451,7 +451,7 @@ static int read_one_entry(const struct object_id *oid, struct strbuf *base,
 {
        struct index_state *istate = context;
        return read_one_entry_opt(istate, oid, base->buf, base->len, pathname,
-                                 mode, stage,
+                                 mode,
                                  ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
 }
 
@@ -465,26 +465,17 @@ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base
 {
        struct index_state *istate = context;
        return read_one_entry_opt(istate, oid, base->buf, base->len, pathname,
-                                 mode, stage,
+                                 mode,
                                  ADD_CACHE_JUST_APPEND);
 }
 
 
-static int read_tree(struct repository *r, struct tree *tree, int stage,
+static int read_tree(struct repository *r, struct tree *tree,
                     struct pathspec *match, struct index_state *istate)
 {
        read_tree_fn_t fn = NULL;
        int i, err;
 
-       /*
-        * Currently the only existing callers of this function all
-        * call it with stage=1 and after making sure there is nothing
-        * at that stage; we could always use read_one_entry_quick().
-        *
-        * But when we decide to straighten out git-read-tree not to
-        * use unpack_trees() in some cases, this will probably start
-        * to matter.
-        */
 
        /*
         * See if we have cache entry at the stage.  If so,
@@ -493,13 +484,13 @@ static int read_tree(struct repository *r, struct tree *tree, int stage,
         */
        for (i = 0; !fn && i < istate->cache_nr; i++) {
                const struct cache_entry *ce = istate->cache[i];
-               if (ce_stage(ce) == stage)
+               if (ce_stage(ce) == 1)
                        fn = read_one_entry;
        }
 
        if (!fn)
                fn = read_one_entry_quick;
-       err = read_tree_recursive(r, tree, "", 0, stage, match, fn, istate);
+       err = read_tree_recursive(r, tree, "", 0, 0, match, fn, istate);
        if (fn == read_one_entry || err)
                return err;
 
@@ -549,7 +540,7 @@ void overlay_tree_on_index(struct index_state *istate,
                               PATHSPEC_PREFER_CWD, prefix, matchbuf);
        } else
                memset(&pathspec, 0, sizeof(pathspec));
-       if (read_tree(the_repository, tree, 1, &pathspec, istate))
+       if (read_tree(the_repository, tree, &pathspec, istate))
                die("unable to read tree entries %s", tree_name);
 
        for (i = 0; i < istate->cache_nr; i++) {