Skip to content

Commit 3c426ec

Browse files
jrngitster
authored andcommitted
gc: improve handling of errors reading gc.log
A collection of minor error handling fixes: - use an error message in lower case, following the usual style - quote filenames in error messages to make them easier to read and to decrease translation load by matching other 'stat' error messages - check for and report errors from 'read', too - avoid being confused by a gc.log larger than INT_MAX bytes Noticed by code inspection. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 53f9a3e commit 3c426ec

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

builtin/gc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,22 +442,25 @@ static int report_last_gc_error(void)
442442
{
443443
struct strbuf sb = STRBUF_INIT;
444444
int ret = 0;
445+
ssize_t len;
445446
struct stat st;
446447
char *gc_log_path = git_pathdup("gc.log");
447448

448449
if (stat(gc_log_path, &st)) {
449450
if (errno == ENOENT)
450451
goto done;
451452

452-
ret = error_errno(_("Can't stat %s"), gc_log_path);
453+
ret = error_errno(_("cannot stat '%s'"), gc_log_path);
453454
goto done;
454455
}
455456

456457
if (st.st_mtime < gc_log_expire_time)
457458
goto done;
458459

459-
ret = strbuf_read_file(&sb, gc_log_path, 0);
460-
if (ret > 0)
460+
len = strbuf_read_file(&sb, gc_log_path, 0);
461+
if (len < 0)
462+
ret = error_errno(_("cannot read '%s'"), gc_log_path);
463+
else if (len > 0)
461464
ret = error(_("The last gc run reported the following. "
462465
"Please correct the root cause\n"
463466
"and remove %s.\n"

0 commit comments

Comments
 (0)