All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
	"Taylor Blau" <me@ttaylorr.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 0/4] usage API: Add and use die_message()
Date: Mon,  6 Dec 2021 17:55:49 +0100	[thread overview]
Message-ID: <cover-0.4-00000000000-20211206T165221Z-avarab@gmail.com> (raw)

A small series to add both die_message() and die_message_errno()
functions. By using these we can make vreportf() in usage.c static.

Doing so opens the door to later feature work on vreportf() that I
submitted an RFC series for[1], but wanted to peel off this more
trivial (and more easy to review) part.

The range-diff below shows changes since the RFC version. There was a
stupid bug of the die_message_errno() helper returning -1 instead of
128 as its die_message() sibling, I also f ixed up the commit messages
a bit, and had builtin/gc.c call "return" instead of "exit()" while I
was at it.

1. https://lore.kernel.org/git/RFC-cover-00.21-00000000000-20211115T220831Z-avarab@gmail.com/

Ævar Arnfjörð Bjarmason (4):
  usage.c: add a die_message() routine
  usage.c API users: use die_message() where appropriate
  usage.c + gc: add and use a die_message_errno()
  config API: don't use vreportf(), make it static in usage.c

 builtin/fast-import.c | 19 +++++++++++--------
 builtin/gc.c          | 21 ++++++++++++---------
 builtin/notes.c       | 15 +++++++++------
 config.c              | 22 +++++++++-------------
 config.h              | 10 ++++++----
 git-compat-util.h     |  4 +++-
 http-backend.c        |  3 ++-
 imap-send.c           |  3 ++-
 parse-options.c       |  2 +-
 run-command.c         | 16 +++++-----------
 usage.c               | 42 ++++++++++++++++++++++++++++++++++++++----
 11 files changed, 98 insertions(+), 59 deletions(-)

Range-diff:
1:  ae05d2398fb ! 1:  5a9ab85fa56 usage.c: add a die_message() routine
    @@ Commit message
         helper routine to bridge this gap in the API.
     
         Functionally this behaves just like the error() routine, except it'll
    -    print a "fatal: " prefix, and it will exit with 128 instead of -1,
    -    this is so that caller can pas the return value to exit(128), instead
    -    of having to hardcode "128".
    +    print a "fatal: " prefix, and it will return with 128 instead of -1,
    +    this is so that caller can pass the return value to "exit()", instead
    +    of having to hardcode "exit(128)".
     
         A subsequent commit will migrate various callers that benefit from
    -    this function over to it, for now we're just adding the routine and
    +    this function over to it. For now we're just adding the routine and
         making die_builtin() in usage.c itself use it.
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
2:  b4ff6ddf986 = 2:  36c050c90c2 usage.c API users: use die_message() where appropriate
3:  f93d95ab288 ! 3:  8747afecdcd usage.c + gc: add and use a die_message_errno()
    @@ Commit message
         errors to use a "fatal: " prefix instead. This adds a sibling function
         to the die_errno() added in a preceding commit.
     
    -    Since it returns 128 instead of -1 we'll need to adjust
    -    report_last_gc_error(). Let's adjust it while we're at it to not
    -    conflate the "should skip" and "exit with this non-zero code"
    -    conditions, as the caller is no longer hardcoding "128", but relying
    -    on die_errno() to return a nen-zero exit() status.
    +    Since it returns 128 instead of -1 (like die_message()) we'll need to
    +    adjust report_last_gc_error().
    +
    +    Let's adjust it while we're at it to not conflate the "should skip"
    +    and "exit with this non-zero code" conditions, as the caller is no
    +    longer hardcoding "128", but relying on die_errno() to return a
    +    nen-zero exit() status.
    +
    +    Since we're touching this code let's also use "return ret" in place of
    +    an "exit(ret)". This is kinder to any cleanup our our "cmd_main()" in
    +    "git.c" might want to do.
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
    @@ builtin/gc.c: int cmd_gc(int argc, const char **argv, const char *prefix)
      				/* Last gc --auto failed. Skip this one. */
      				return 0;
     +			if (ret)
    -+				/* an error occurred, already reported */
    -+				exit(ret);
    ++				/* an I/O error occurred, already reported */
    ++				return ret;
      
      			if (lock_repo_for_gc(force, &pid))
      				return 0;
    @@ usage.c: int die_message(const char *err, ...)
     +	va_start(params, fmt);
     +	die_message_routine(fmt_with_err(buf, sizeof(buf), fmt), params);
     +	va_end(params);
    -+	return -1;
    ++	return 128;
     +}
     +
      #undef error_errno
4:  40fe7cf81a8 = 4:  e0e6427cbd3 config API: don't use vreportf(), make it static in usage.c
-- 
2.34.1.898.g5a552c2e5f0


             reply	other threads:[~2021-12-06 17:04 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 16:55 Ævar Arnfjörð Bjarmason [this message]
2021-12-06 16:55 ` [PATCH 1/4] usage.c: add a die_message() routine Ævar Arnfjörð Bjarmason
2021-12-06 19:42   ` Junio C Hamano
2021-12-06 19:46     ` Junio C Hamano
2021-12-06 16:55 ` [PATCH 2/4] usage.c API users: use die_message() where appropriate Ævar Arnfjörð Bjarmason
2021-12-06 20:00   ` Junio C Hamano
2021-12-06 16:55 ` [PATCH 3/4] usage.c + gc: add and use a die_message_errno() Ævar Arnfjörð Bjarmason
2021-12-06 21:19   ` Junio C Hamano
2021-12-06 16:55 ` [PATCH 4/4] config API: don't use vreportf(), make it static in usage.c Ævar Arnfjörð Bjarmason
2021-12-06 21:26   ` Junio C Hamano
2021-12-07 18:05     ` Ævar Arnfjörð Bjarmason
2021-12-07 18:26 ` [PATCH v2 0/6] usage API: Add and use die_message() Ævar Arnfjörð Bjarmason
2021-12-07 18:26   ` [PATCH v2 1/6] usage.c: add a die_message() routine Ævar Arnfjörð Bjarmason
2021-12-07 18:26   ` [PATCH v2 2/6] usage.c API users: use die_message() for "fatal :" + exit 128 Ævar Arnfjörð Bjarmason
2021-12-07 18:26   ` [PATCH v2 3/6] usage.c API users: use die_message() for error() " Ævar Arnfjörð Bjarmason
2021-12-07 18:26   ` [PATCH v2 4/6] gc: return from cmd_gc(), don't call exit() Ævar Arnfjörð Bjarmason
2021-12-07 18:26   ` [PATCH v2 5/6] usage.c + gc: add and use a die_message_errno() Ævar Arnfjörð Bjarmason
2021-12-07 18:26   ` [PATCH v2 6/6] config API: use get_error_routine(), not vreportf() Ævar Arnfjörð Bjarmason
2021-12-07 21:24   ` [PATCH v2 0/6] usage API: Add and use die_message() Junio C Hamano
2021-12-22 18:57   ` Jonathan Tan
2021-12-22 19:59     ` Junio C Hamano
2021-12-24 17:01     ` Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover-0.4-00000000000-20211206T165221Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=me@ttaylorr.com \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.