On Wed, May 16, 2018 at 03:21:09PM -0700, Stefan Beller wrote:
> A common pattern with the repo_read_index function is to die if the return
> of repo_read_index is negative. Move this pattern into a function.
>
> This patch replaces the calls of repo_read_index with its _or_die version,
> if the error message is exactly the same.
>
> Signed-off-by: Stefan Beller <[email protected]>
> ---
> builtin/add.c | 3 +--
> builtin/check-ignore.c | 7 ++++---
> builtin/clean.c | 4 ++--
> builtin/mv.c | 3 +--
> builtin/reset.c | 3 +--
> builtin/rm.c | 3 +--
> builtin/submodule--helper.c | 3 +--
'git grep -w -A3 read_cache' tells me you're missing (*)
builtin/diff-tree.c: if (read_cache() < 0)
builtin/diff-tree.c- die(_("index file corrupt"));
builtin/merge-ours.c: if (read_cache() < 0)
builtin/merge-ours.c: die_errno("read_cache failed");
builtin/update-index.c: entries = read_cache();
builtin/update-index.c- if (entries < 0)
builtin/update-index.c- die("cache corrupted");
merge-ours.c is interesting because it uses die_errno() version
instead. I think that might give inaccurate diagnostics because we do
not only fail when a libc/system call fails in read_cache(), so it
should be safe to just use die() here.
update-index.c is also interesting because it actually saves the
return value. I don't think it's used anywhere, so you can just drop
that 'entries' variable. But perhaps it's good to make
repo_read_index_or_die() return the number of entries too.
(*) yes yes you did mention "if the error message is exactly the
same". But these look like good candicates to convert anyway
--
Duy