summaryrefslogtreecommitdiff
path: root/git-compat-util.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-06-10 15:04:15 -0700
committerJunio C Hamano <gitster@pobox.com>2022-06-10 15:04:15 -0700
commit4da14b574f2e52eb05e4fef7ed169a8f9e3a8b67 (patch)
tree134a132278b3ca34974f2812b24acb5fe9a47810 /git-compat-util.h
parent28c2a3599730cca72c587bec7a9a72705635d992 (diff)
parent6d40f0ad15e72daab6524988c9c4b4a3460488f8 (diff)
downloadgit-4da14b574f2e52eb05e4fef7ed169a8f9e3a8b67.tar.gz
Merge branch 'ab/bug-if-bug'
A new bug() and BUG_if_bug() API is introduced to make it easier to uniformly log "detect multiple bugs and abort in the end" pattern. * ab/bug-if-bug: cache-tree.c: use bug() and BUG_if_bug() receive-pack: use bug() and BUG_if_bug() parse-options.c: use optbug() instead of BUG() "opts" check parse-options.c: use new bug() API for optbug() usage.c: add a non-fatal bug() function to go with BUG() common-main.c: move non-trace2 exit() behavior out of trace2.c
Diffstat (limited to 'git-compat-util.h')
-rw-r--r--git-compat-util.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index d9457b9aae..fd36d3bfdc 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -1326,9 +1326,19 @@ static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
/* usage.c: only to be used for testing BUG() implementation (see test-tool) */
extern int BUG_exit_code;
+/* usage.c: if bug() is called we should have a BUG_if_bug() afterwards */
+extern int bug_called_must_BUG;
+
__attribute__((format (printf, 3, 4))) NORETURN
void BUG_fl(const char *file, int line, const char *fmt, ...);
#define BUG(...) BUG_fl(__FILE__, __LINE__, __VA_ARGS__)
+__attribute__((format (printf, 3, 4)))
+void bug_fl(const char *file, int line, const char *fmt, ...);
+#define bug(...) bug_fl(__FILE__, __LINE__, __VA_ARGS__)
+#define BUG_if_bug(...) do { \
+ if (bug_called_must_BUG) \
+ BUG_fl(__FILE__, __LINE__, __VA_ARGS__); \
+} while (0)
#ifndef FSYNC_METHOD_DEFAULT
#ifdef __APPLE__
@@ -1459,8 +1469,8 @@ int cmd_main(int, const char **);
* Intercept all calls to exit() and route them to trace2 to
* optionally emit a message before calling the real exit().
*/
-int trace2_cmd_exit_fl(const char *file, int line, int code);
-#define exit(code) exit(trace2_cmd_exit_fl(__FILE__, __LINE__, (code)))
+int common_exit(const char *file, int line, int code);
+#define exit(code) exit(common_exit(__FILE__, __LINE__, (code)))
/*
* You can mark a stack variable with UNLEAK(var) to avoid it being