summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-01-10 19:52:53 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-01-10 19:52:53 (GMT)
commit4b51386bbfc5d26e552c3c4be135e31cd2f64b44 (patch)
tree5bff7a8a4dee06d92dca0a89976248dc7e571918 /builtin
parentbc61dbac770923a96e2007c3de4027c5d11c6d41 (diff)
parentf5c39c3268107e1f3def70709d509fd24282832c (diff)
downloadgit-4b51386bbfc5d26e552c3c4be135e31cd2f64b44.zip
git-4b51386bbfc5d26e552c3c4be135e31cd2f64b44.tar.gz
git-4b51386bbfc5d26e552c3c4be135e31cd2f64b44.tar.bz2
Merge branch 'ab/usage-die-message'
Code clean-up to hide vreportf() from public API. * ab/usage-die-message: config API: use get_error_routine(), not vreportf() usage.c + gc: add and use a die_message_errno() gc: return from cmd_gc(), don't call exit() usage.c API users: use die_message() for error() + exit 128 usage.c API users: use die_message() for "fatal :" + exit 128 usage.c: add a die_message() routine
Diffstat (limited to 'builtin')
-rw-r--r--builtin/fast-import.c12
-rw-r--r--builtin/gc.c14
-rw-r--r--builtin/notes.c9
3 files changed, 20 insertions, 15 deletions
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 20406f6..2b2e28b 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -401,16 +401,18 @@ static void dump_marks(void);
static NORETURN void die_nicely(const char *err, va_list params)
{
+ va_list cp;
static int zombie;
- char message[2 * PATH_MAX];
+ report_fn die_message_fn = get_die_message_routine();
- vsnprintf(message, sizeof(message), err, params);
- fputs("fatal: ", stderr);
- fputs(message, stderr);
- fputc('\n', stderr);
+ va_copy(cp, params);
+ die_message_fn(err, params);
if (!zombie) {
+ char message[2 * PATH_MAX];
+
zombie = 1;
+ vsnprintf(message, sizeof(message), err, cp);
write_crash_report(message);
end_packfile();
unkeep_all_packs();
diff --git a/builtin/gc.c b/builtin/gc.c
index bcef6a4..8e60ef1 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -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
@@ -611,12 +612,13 @@ 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 */
- exit(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;
diff --git a/builtin/notes.c b/builtin/notes.c
index 118db9e..05d6048 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -200,11 +200,12 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
static void write_note_data(struct note_data *d, struct object_id *oid)
{
if (write_object_file(d->buf.buf, d->buf.len, blob_type, oid)) {
- error(_("unable to write note object"));
+ int status = die_message(_("unable to write note object"));
+
if (d->edit_path)
- error(_("the note contents have been left in %s"),
- d->edit_path);
- exit(128);
+ die_message(_("the note contents have been left in %s"),
+ d->edit_path);
+ exit(status);
}
}