[PATCH 0/4] usage API: Add and use die_message()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx/

Æ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@xxxxxxxxx>
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@xxxxxxxxx>
     
    @@ 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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux