Skip to content

Commit 9c5f3ee

Browse files
avargitster
authored andcommitted
read-cache API & users: make discard_index() return void
The discard_index() function has not returned non-zero since 7a51ed6 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fbc1ed6 commit 9c5f3ee

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

add-interactive.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ static int get_modified_files(struct repository *r,
530530
struct collection_status s = { 0 };
531531
int i;
532532

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)
535535
return error(_("could not read index"));
536536

537537
prefix_item_list_clear(files);
@@ -1156,8 +1156,8 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
11561156
_("staged"), _("unstaged"), _("path"));
11571157
opts.list_opts.header = header.buf;
11581158

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 ||
11611161
repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,
11621162
NULL, NULL, NULL) < 0)
11631163
warning(_("could not refresh index"));

add-patch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,8 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
17501750
s.mode = &patch_mode_add;
17511751
s.revision = revision;
17521752

1753-
if (discard_index(r->index) < 0 || repo_read_index(r) < 0 ||
1753+
discard_index(r->index);
1754+
if (repo_read_index(r) < 0 ||
17541755
(!s.mode->index_only &&
17551756
repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,
17561757
NULL, NULL, NULL) < 0) ||

builtin/merge.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ static void restore_state(const struct object_id *head,
390390
run_command(&cmd);
391391

392392
refresh_cache:
393-
if (discard_cache() < 0 || read_cache() < 0)
393+
discard_cache();
394+
if (read_cache() < 0)
394395
die(_("could not read index"));
395396
}
396397

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ void ensure_full_index(struct index_state *istate);
774774
*/
775775
int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
776776

777-
int discard_index(struct index_state *);
777+
void discard_index(struct index_state *);
778778
void move_index_extensions(struct index_state *dst, struct index_state *src);
779779
int unmerged_index(const struct index_state *);
780780

read-cache.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,7 +2531,7 @@ int is_index_unborn(struct index_state *istate)
25312531
return (!istate->cache_nr && !istate->timestamp.sec);
25322532
}
25332533

2534-
int discard_index(struct index_state *istate)
2534+
void discard_index(struct index_state *istate)
25352535
{
25362536
/*
25372537
* Cache entries in istate->cache[] should have been allocated
@@ -2562,8 +2562,6 @@ int discard_index(struct index_state *istate)
25622562
mem_pool_discard(istate->ce_mem_pool, should_validate_cache_entries());
25632563
FREE_AND_NULL(istate->ce_mem_pool);
25642564
}
2565-
2566-
return 0;
25672565
}
25682566

25692567
/*

sequencer.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3564,7 +3564,8 @@ static int do_exec(struct repository *r, const char *command_line)
35643564
status = run_command(&cmd);
35653565

35663566
/* 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)
35683569
return error(_("could not read index"));
35693570

35703571
dirty = require_clean_work_tree(r, "rebase", NULL, 1, 1);
@@ -4029,9 +4030,11 @@ static int do_merge(struct repository *r,
40294030
ret = run_command(&cmd);
40304031

40314032
/* 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+
}
40354038
goto leave_merge;
40364039
}
40374040

@@ -4404,8 +4407,8 @@ void create_autostash(struct repository *r, const char *path)
44044407
printf(_("Created autostash: %s\n"), buf.buf);
44054408
if (reset_head(r, &ropts) < 0)
44064409
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)
44094412
die(_("could not read index"));
44104413
}
44114414
strbuf_release(&buf);

0 commit comments

Comments
 (0)