Skip to content

Commit 3755077

Browse files
peffgitster
authored andcommitted
diff: die when failing to read index in git-diff builtin
When the git-diff program fails to read the index in its diff-files or diff-index helper functions, it propagates the error up the stack. This eventually lands in diff_result_code(), which does not handle it well (as discussed in the previous patch). Since the only sensible thing here is to exit with an error code (and what we were expecting the propagated error code to cause), let's just do that directly. There's no test here, as I'm not even sure this case can be triggered. The index-reading functions tend to die() themselves when encountering any errors, and the return value is just the number of entries in the file (and so always 0 or positive). But let's err on the conservative side and keep checking the return value. It may be worth digging into as a separate topic (though index-reading is low-level enough that we probably want to eventually teach it to propagate errors anyway for lib-ification purposes, at which point this code would already be doing the right thing). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ad6e2b commit 3755077

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

builtin/diff.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,10 @@ static int builtin_diff_index(struct rev_info *revs,
163163
setup_work_tree();
164164
if (repo_read_index_preload(the_repository,
165165
&revs->diffopt.pathspec, 0) < 0) {
166-
perror("repo_read_index_preload");
167-
return -1;
166+
die_errno("repo_read_index_preload");
168167
}
169168
} else if (repo_read_index(the_repository) < 0) {
170-
perror("repo_read_cache");
171-
return -1;
169+
die_errno("repo_read_cache");
172170
}
173171
return run_diff_index(revs, option);
174172
}
@@ -289,8 +287,7 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
289287
setup_work_tree();
290288
if (repo_read_index_preload(the_repository, &revs->diffopt.pathspec,
291289
0) < 0) {
292-
perror("repo_read_index_preload");
293-
return -1;
290+
die_errno("repo_read_index_preload");
294291
}
295292
return run_diff_files(revs, options);
296293
}

0 commit comments

Comments
 (0)