]> git.ipfire.org Git - thirdparty/git.git/commitdiff
read-cache API & users: make discard_index() return void
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Sat, 19 Nov 2022 13:07:31 +0000 (14:07 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 Nov 2022 03:06:15 +0000 (12:06 +0900)
The discard_index() function has not returned non-zero since
7a51ed66f65 (Make on-disk index representation separate from in-core
one, 2008-01-14), but we've had various code in-tree still acting as
though that might be the case.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
add-interactive.c
add-patch.c
builtin/merge.c
cache.h
read-cache.c
sequencer.c

index ecc5ae1b2499c56beae72ec4756011b4b8296134..ae1839c04a7fa27125e4a2308c971e63da18492a 100644 (file)
@@ -530,8 +530,8 @@ static int get_modified_files(struct repository *r,
        struct collection_status s = { 0 };
        int i;
 
-       if (discard_index(r->index) < 0 ||
-           repo_read_index_preload(r, ps, 0) < 0)
+       discard_index(r->index);
+       if (repo_read_index_preload(r, ps, 0) < 0)
                return error(_("could not read index"));
 
        prefix_item_list_clear(files);
@@ -1156,8 +1156,8 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
                    _("staged"), _("unstaged"), _("path"));
        opts.list_opts.header = header.buf;
 
-       if (discard_index(r->index) < 0 ||
-           repo_read_index(r) < 0 ||
+       discard_index(r->index);
+       if (repo_read_index(r) < 0 ||
            repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,
                                         NULL, NULL, NULL) < 0)
                warning(_("could not refresh index"));
index 33ecd8398a12707836cd89975226179413fa9574..a86a92e16461384cbe8ac880fa6515e0f74e243c 100644 (file)
@@ -1750,7 +1750,8 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
                s.mode = &patch_mode_add;
        s.revision = revision;
 
-       if (discard_index(r->index) < 0 || repo_read_index(r) < 0 ||
+       discard_index(r->index);
+       if (repo_read_index(r) < 0 ||
            (!s.mode->index_only &&
             repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,
                                          NULL, NULL, NULL) < 0) ||
index da11dfae19e546cc3f23d0177eb67ef61600d941..89fdac24e40864f71e2d4da54d8c73cf391aa0d0 100644 (file)
@@ -390,7 +390,8 @@ static void restore_state(const struct object_id *head,
        run_command(&cmd);
 
 refresh_cache:
-       if (discard_cache() < 0 || read_cache() < 0)
+       discard_cache();
+       if (read_cache() < 0)
                die(_("could not read index"));
 }
 
diff --git a/cache.h b/cache.h
index 53dc43417172622731d6e10338d4c53d8863e60a..489e9e1925b71423af6416b39e7e9bbcec02c050 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -774,7 +774,7 @@ void ensure_full_index(struct index_state *istate);
  */
 int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
 
-int discard_index(struct index_state *);
+void discard_index(struct index_state *);
 void move_index_extensions(struct index_state *dst, struct index_state *src);
 int unmerged_index(const struct index_state *);
 
index 32024029274828c12654e3c256de3d8d08f37734..46f5e497b142a912ca27a19ad2defb6f50ba4f89 100644 (file)
@@ -2531,7 +2531,7 @@ int is_index_unborn(struct index_state *istate)
        return (!istate->cache_nr && !istate->timestamp.sec);
 }
 
-int discard_index(struct index_state *istate)
+void discard_index(struct index_state *istate)
 {
        /*
         * Cache entries in istate->cache[] should have been allocated
@@ -2562,8 +2562,6 @@ int discard_index(struct index_state *istate)
                mem_pool_discard(istate->ce_mem_pool, should_validate_cache_entries());
                FREE_AND_NULL(istate->ce_mem_pool);
        }
-
-       return 0;
 }
 
 /*
index a46f3ad2e33761c310c2d01e0dd68069559044bd..746a71cdc9229333bd527cd0b836926e44d17b31 100644 (file)
@@ -3564,7 +3564,8 @@ static int do_exec(struct repository *r, const char *command_line)
        status = run_command(&cmd);
 
        /* force re-reading of the cache */
-       if (discard_index(r->index) < 0 || repo_read_index(r) < 0)
+       discard_index(r->index);
+       if (repo_read_index(r) < 0)
                return error(_("could not read index"));
 
        dirty = require_clean_work_tree(r, "rebase", NULL, 1, 1);
@@ -4029,9 +4030,11 @@ static int do_merge(struct repository *r,
                ret = run_command(&cmd);
 
                /* force re-reading of the cache */
-               if (!ret && (discard_index(r->index) < 0 ||
-                            repo_read_index(r) < 0))
-                       ret = error(_("could not read index"));
+               if (!ret) {
+                       discard_index(r->index);
+                       if (repo_read_index(r) < 0)
+                               ret = error(_("could not read index"));
+               }
                goto leave_merge;
        }
 
@@ -4404,8 +4407,8 @@ void create_autostash(struct repository *r, const char *path)
                printf(_("Created autostash: %s\n"), buf.buf);
                if (reset_head(r, &ropts) < 0)
                        die(_("could not reset --hard"));
-               if (discard_index(r->index) < 0 ||
-                       repo_read_index(r) < 0)
+               discard_index(r->index);
+               if (repo_read_index(r) < 0)
                        die(_("could not read index"));
        }
        strbuf_release(&buf);