]> git.ipfire.org Git - thirdparty/git.git/commitdiff
usage.c + gc: add and use a die_message_errno()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Tue, 7 Dec 2021 18:26:33 +0000 (19:26 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Dec 2021 21:25:16 +0000 (13:25 -0800)
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 <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/gc.c
git-compat-util.h
usage.c

index 900ccfb8d48d03931ccd1c656f6ff936817188b4..8e60ef1eaba426eae66c99d15d5dfdcbc26efac4 100644 (file)
@@ -470,7 +470,8 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
 /*
  * Returns 0 if there was no previous error and gc can proceed, 1 if
  * gc should not proceed due to an error in the last run. Prints a
- * message and returns -1 if an error occurred while reading gc.log
+ * message and returns with a non-[01] status code if an error occurred
+ * while reading gc.log
  */
 static int report_last_gc_error(void)
 {
@@ -484,7 +485,7 @@ static int report_last_gc_error(void)
                if (errno == ENOENT)
                        goto done;
 
-               ret = error_errno(_("cannot stat '%s'"), gc_log_path);
+               ret = die_message_errno(_("cannot stat '%s'"), gc_log_path);
                goto done;
        }
 
@@ -493,7 +494,7 @@ static int report_last_gc_error(void)
 
        len = strbuf_read_file(&sb, gc_log_path, 0);
        if (len < 0)
-               ret = error_errno(_("cannot read '%s'"), gc_log_path);
+               ret = die_message_errno(_("cannot read '%s'"), gc_log_path);
        else if (len > 0) {
                /*
                 * 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)
                if (detach_auto) {
                        int ret = report_last_gc_error();
 
-                       if (ret < 0)
-                               /* an I/O error occurred, already reported */
-                               return 128;
                        if (ret == 1)
                                /* Last gc --auto failed. Skip this one. */
                                return 0;
+                       else if (ret)
+                               /* an I/O error occurred, already reported */
+                               return ret;
 
                        if (lock_repo_for_gc(force, &pid))
                                return 0;
index d5e495529c8b83c492b0118a6a64261505945538..c6c6f7d6b51d9ff4f4bada247bf3b7e06809ec91 100644 (file)
@@ -480,6 +480,7 @@ NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2))
 NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));
 NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
 int die_message(const char *err, ...) __attribute__((format (printf, 1, 2)));
+int die_message_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
 int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
 int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
 void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
diff --git a/usage.c b/usage.c
index 76399ba84096035f016286a0fc09e2a0d84ca467..3d09e8eea48abedd61cec4ed7ff93d12b079b74a 100644 (file)
--- a/usage.c
+++ b/usage.c
@@ -233,6 +233,18 @@ int die_message(const char *err, ...)
        return 128;
 }
 
+#undef die_message_errno
+int die_message_errno(const char *fmt, ...)
+{
+       char buf[1024];
+       va_list params;
+
+       va_start(params, fmt);
+       die_message_routine(fmt_with_err(buf, sizeof(buf), fmt), params);
+       va_end(params);
+       return 128;
+}
+
 #undef error_errno
 int error_errno(const char *fmt, ...)
 {