tr2: do compiler enum check in trace2_collect_process_info()
Change code added in 2f732bf15e6 (tr2: log parent process name, 2021-07-21) to use a switch statement without a "default" branch to have the compiler error if this code ever drifts out of sync with the members of the "enum trace2_process_info_reason". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Acked-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Aug 27, 2021 at 10:02 UTC
326460a8700c4bc025578da18509c77f72928950
1 file changed
+7
-6
compat/linux/procinfo.c
+7
-6
@@ -31,29 +31,30 @@ static void get_ancestry_names(struct strvec *names)
31
32
void trace2_collect_process_info(enum trace2_process_info_reason reason)
33
{
34
+ struct strvec names = STRVEC_INIT;
35
+
36
if (!trace2_is_enabled())
37
return;
38
37
- if (reason == TRACE2_PROCESS_INFO_EXIT)
39
+ switch (reason) {
40
+ case TRACE2_PROCESS_INFO_EXIT:
41
/*
42
* The Windows version of this calls its
43
* get_peak_memory_info() here. We may want to insert
44
* similar process-end statistics here in the future.
45
*/
43
- return;
44
-
45
- if (reason == TRACE2_PROCESS_INFO_STARTUP) {
46
+ break;
47
+ case TRACE2_PROCESS_INFO_STARTUP:
48
/*
49
* NEEDSWORK: we could do the entire ptree in an array instead,
50
* see compat/win32/trace2_win32_process_info.c.
51
*/
50
- struct strvec names = STRVEC_INIT;
51
-
52
get_ancestry_names(&names);
53
54
if (names.nr)
55
trace2_cmd_ancestry(names.v);
56
strvec_clear(&names);
57
+ break;
58
}
59
60
return;