]> git.ipfire.org Git - thirdparty/git.git/commitdiff
usage: add trace2 entry upon warning()
authorJonathan Tan <jonathantanmy@google.com>
Mon, 23 Nov 2020 20:45:22 +0000 (12:45 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Nov 2020 01:39:38 +0000 (17:39 -0800)
Emit a trace2 error event whenever warning() is called, just like when
die(), error(), or usage() is called.

This helps debugging issues that would trigger warnings but not errors.
In particular, this might have helped debugging an issue I encountered
with commit graphs at $DAYJOB [1].

There is a tradeoff between including potentially relevant messages and
cluttering up the trace output produced. I think that warning() messages
should be included in traces, because by its nature, Git is used over
multiple invocations of the Git tool, and a failure (currently traced)
in a Git invocation might be caused by an unexpected interaction in a
previous Git invocation that only has a warning (currently untraced) as
a symptom - as is the case in [1].

[1] https://lore.kernel.org/git/20200629220744.1054093-1-jonathantanmy@google.com/

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/technical/api-trace2.txt
usage.c

index 6b6085585d5659ea6427247c18c96c84fdef5ade..c65ffafc4854bb74cb2398910e6da30982b2e971 100644 (file)
@@ -466,7 +466,7 @@ completed.)
 
 `"error"`::
        This event is emitted when one of the `error()`, `die()`,
-       or `usage()` functions are called.
+       `warning()`, or `usage()` functions are called.
 +
 ------------
 {
diff --git a/usage.c b/usage.c
index 58fb5fff5f245c33898e27c85296a4a47325c34e..7c58b2688cbe0ba8e1b1b31a4d2e342c625eeb48 100644 (file)
--- a/usage.c
+++ b/usage.c
@@ -81,6 +81,12 @@ static void error_builtin(const char *err, va_list params)
 
 static void warn_builtin(const char *warn, va_list params)
 {
+       /*
+        * We call this trace2 function first and expect it to va_copy 'params'
+        * before using it (because an 'ap' can only be walked once).
+        */
+       trace2_cmd_error_va(warn, params);
+
        vreportf("warning: ", warn, params);
 }