]> git.ipfire.org Git - thirdparty/git.git/commit
usage: allow dying without writing an error message
authorPatrick Steinhardt <ps@pks.im>
Tue, 3 Jun 2025 14:01:18 +0000 (16:01 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Jun 2025 15:30:51 +0000 (08:30 -0700)
commit697202b0b1c7c02208c620f96c608e0817d079dd
treea3b7a86fcb6aa48d45876abfd600659361aa0b44
parentc367852d9e3c114fe02e16f4d56f259f12188e2a
usage: allow dying without writing an error message

Sometimes code wants to die in a situation where it already has written
an error message. To use the same error code as `die()` we have to use
`exit(128)`, which is easy to get wrong and leaves magic numbers all
over our codebase.

Teach `die_message_builtin()` to not print any error when passed a
`NULL` pointer as error string. Like this, such users can now call
`die(NULL)` to achieve the same result without any hardcoded error
codes.

Adapt a couple of builtins to use this new pattern to demonstrate that
there is a need for such a helper.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/am.c
builtin/checkout.c
builtin/fetch.c
builtin/submodule--helper.c
usage.c