aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/checkout.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-06-03 16:01:18 +0200
committerJunio C Hamano <gitster@pobox.com>2025-06-03 08:30:51 -0700
commit697202b0b1c7c02208c620f96c608e0817d079dd (patch)
treea3b7a86fcb6aa48d45876abfd600659361aa0b44 /builtin/checkout.c
parentbuiltin/maintenance: fix locking race with refs and reflogs tasks (diff)
downloadgit-697202b0b1c7c02208c620f96c608e0817d079dd.tar.gz
git-697202b0b1c7c02208c620f96c608e0817d079dd.zip
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>
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r--builtin/checkout.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index d185982f3a..536192d345 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -838,7 +838,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
init_tree_desc(&trees[0], &tree->object.oid,
tree->buffer, tree->size);
if (parse_tree(new_tree) < 0)
- exit(128);
+ die(NULL);
tree = new_tree;
init_tree_desc(&trees[1], &tree->object.oid,
tree->buffer, tree->size);
@@ -913,7 +913,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
work,
old_tree);
if (ret < 0)
- exit(128);
+ die(NULL);
ret = reset_tree(new_tree,
opts, 0,
writeout_error, new_branch_info);