Skip to content

Commit 24f6e6d

Browse files
avargitster
authored andcommitted
usage.c + gc: add and use a die_message_errno()
Change the "error: " output when we exit with 128 due to gc.log errors to use a "fatal: " prefix instead. To do this add a die_message_errno() a sibling function to the die_errno() added in a preceding commit. Before this we'd expect report_last_gc_error() to return -1 from error_errno() in this case. It already treated a status of 0 and 1 specially. Let's just document that anything that's not 0 or 1 should be returned. We could also retain the "ret < 0" behavior here without hardcoding 128 by returning -128, and having the caller do a "return -ret", but I think this makes more sense, and preserves the path from die_message*()'s return value to the "return" without hardcoding "128". Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0faf84d commit 24f6e6d

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

builtin/gc.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
470470
/*
471471
* Returns 0 if there was no previous error and gc can proceed, 1 if
472472
* gc should not proceed due to an error in the last run. Prints a
473-
* message and returns -1 if an error occurred while reading gc.log
473+
* message and returns with a non-[01] status code if an error occurred
474+
* while reading gc.log
474475
*/
475476
static int report_last_gc_error(void)
476477
{
@@ -484,7 +485,7 @@ static int report_last_gc_error(void)
484485
if (errno == ENOENT)
485486
goto done;
486487

487-
ret = error_errno(_("cannot stat '%s'"), gc_log_path);
488+
ret = die_message_errno(_("cannot stat '%s'"), gc_log_path);
488489
goto done;
489490
}
490491

@@ -493,7 +494,7 @@ static int report_last_gc_error(void)
493494

494495
len = strbuf_read_file(&sb, gc_log_path, 0);
495496
if (len < 0)
496-
ret = error_errno(_("cannot read '%s'"), gc_log_path);
497+
ret = die_message_errno(_("cannot read '%s'"), gc_log_path);
497498
else if (len > 0) {
498499
/*
499500
* A previous gc failed. Report the error, and don't
@@ -612,12 +613,12 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
612613
if (detach_auto) {
613614
int ret = report_last_gc_error();
614615

615-
if (ret < 0)
616-
/* an I/O error occurred, already reported */
617-
return 128;
618616
if (ret == 1)
619617
/* Last gc --auto failed. Skip this one. */
620618
return 0;
619+
else if (ret)
620+
/* an I/O error occurred, already reported */
621+
return ret;
621622

622623
if (lock_repo_for_gc(force, &pid))
623624
return 0;

git-compat-util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2))
480480
NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));
481481
NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
482482
int die_message(const char *err, ...) __attribute__((format (printf, 1, 2)));
483+
int die_message_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
483484
int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
484485
int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
485486
void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));

usage.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ int die_message(const char *err, ...)
233233
return 128;
234234
}
235235

236+
#undef die_message_errno
237+
int die_message_errno(const char *fmt, ...)
238+
{
239+
char buf[1024];
240+
va_list params;
241+
242+
va_start(params, fmt);
243+
die_message_routine(fmt_with_err(buf, sizeof(buf), fmt), params);
244+
va_end(params);
245+
return 128;
246+
}
247+
236248
#undef error_errno
237249
int error_errno(const char *fmt, ...)
238250
{

0 commit comments

Comments
 (0)