read-cache API & users: make discard_index() return void
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>
Ævar Arnfjörð Bjarmason committed
Nov 19, 2022 at 14:07 UTC
9c5f3ee3b3a04182cc22630e9eb9fad95bd57fd7
6 files changed
+19
-16
add-interactive.c
+4
-4
@@ -530,8 +530,8 @@ static int get_modified_files(struct repository *r,
530
struct collection_status s = { 0 };
531
int i;
532
533
- if (discard_index(r->index) < 0 ||
534
- repo_read_index_preload(r, ps, 0) < 0)
533
+ discard_index(r->index);
534
+ if (repo_read_index_preload(r, ps, 0) < 0)
535
return error(_("could not read index"));
536
537
prefix_item_list_clear(files);
@@ -1156,8 +1156,8 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
1156
_("staged"), _("unstaged"), _("path"));
1157
opts.list_opts.header = header.buf;
1158
1159
- if (discard_index(r->index) < 0 ||
1160
- repo_read_index(r) < 0 ||
1159
+ discard_index(r->index);
1160
+ if (repo_read_index(r) < 0 ||
1161
repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,
1162
NULL, NULL, NULL) < 0)
1163
warning(_("could not refresh index"));
add-patch.c
+2
-1
@@ -1750,7 +1750,8 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
1750
s.mode = &patch_mode_add;
1751
s.revision = revision;
1752
1753
- if (discard_index(r->index) < 0 || repo_read_index(r) < 0 ||
1753
+ discard_index(r->index);
1754
+ if (repo_read_index(r) < 0 ||
1755
(!s.mode->index_only &&
1756
repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,
1757
NULL, NULL, NULL) < 0) ||
builtin/merge.c
+2
-1
@@ -390,7 +390,8 @@ static void restore_state(const struct object_id *head,
390
run_command(&cmd);
391
392
refresh_cache:
393
- if (discard_cache() < 0 || read_cache() < 0)
393
+ discard_cache();
394
+ if (read_cache() < 0)
395
die(_("could not read index"));
396
}
397
cache.h
+1
-1
@@ -774,7 +774,7 @@ void ensure_full_index(struct index_state *istate);
774
*/
775
int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
776
777
-int discard_index(struct index_state *);
777
+void discard_index(struct index_state *);
778
void move_index_extensions(struct index_state *dst, struct index_state *src);
779
int unmerged_index(const struct index_state *);
780
read-cache.c
+1
-3
@@ -2531,7 +2531,7 @@ int is_index_unborn(struct index_state *istate)
2531
return (!istate->cache_nr && !istate->timestamp.sec);
2532
}
2533
2534
-int discard_index(struct index_state *istate)
2534
+void discard_index(struct index_state *istate)
2535
{
2536
/*
2537
* Cache entries in istate->cache[] should have been allocated
@@ -2562,8 +2562,6 @@ int discard_index(struct index_state *istate)
2562
mem_pool_discard(istate->ce_mem_pool, should_validate_cache_entries());
2563
FREE_AND_NULL(istate->ce_mem_pool);
2564
}
2565
-
2566
- return 0;
2565
}
2566
2567
/*
sequencer.c
+9
-6
@@ -3564,7 +3564,8 @@ static int do_exec(struct repository *r, const char *command_line)
3564
status = run_command(&cmd);
3565
3566
/* force re-reading of the cache */
3567
- if (discard_index(r->index) < 0 || repo_read_index(r) < 0)
3567
+ discard_index(r->index);
3568
+ if (repo_read_index(r) < 0)
3569
return error(_("could not read index"));
3570
3571
dirty = require_clean_work_tree(r, "rebase", NULL, 1, 1);
@@ -4029,9 +4030,11 @@ static int do_merge(struct repository *r,
4030
ret = run_command(&cmd);
4031
4032
/* force re-reading of the cache */
4032
- if (!ret && (discard_index(r->index) < 0 ||
4033
- repo_read_index(r) < 0))
4034
- ret = error(_("could not read index"));
4033
+ if (!ret) {
4034
+ discard_index(r->index);
4035
+ if (repo_read_index(r) < 0)
4036
+ ret = error(_("could not read index"));
4037
+ }
4038
goto leave_merge;
4039
}
4040
@@ -4404,8 +4407,8 @@ void create_autostash(struct repository *r, const char *path)
4407
printf(_("Created autostash: %s\n"), buf.buf);
4408
if (reset_head(r, &ropts) < 0)
4409
die(_("could not reset --hard"));
4407
- if (discard_index(r->index) < 0 ||
4408
- repo_read_index(r) < 0)
4410
+ discard_index(r->index);
4411
+ if (repo_read_index(r) < 0)
4412
die(_("could not read index"));
4413
}
4414
strbuf_release(&buf);