Merge branch 'sg/name-rev-cutoff-underflow-fix'
[git] / trace2 / tr2_cmd_name.c
1 #include "cache.h"
2 #include "trace2/tr2_cmd_name.h"
3
4 #define TR2_ENVVAR_PARENT_NAME "GIT_TRACE2_PARENT_NAME"
5
6 static struct strbuf tr2cmdname_hierarchy = STRBUF_INIT;
7
8 void tr2_cmd_name_append_hierarchy(const char *name)
9 {
10         const char *parent_name = getenv(TR2_ENVVAR_PARENT_NAME);
11
12         strbuf_reset(&tr2cmdname_hierarchy);
13         if (parent_name && *parent_name) {
14                 strbuf_addstr(&tr2cmdname_hierarchy, parent_name);
15                 strbuf_addch(&tr2cmdname_hierarchy, '/');
16         }
17         strbuf_addstr(&tr2cmdname_hierarchy, name);
18
19         setenv(TR2_ENVVAR_PARENT_NAME, tr2cmdname_hierarchy.buf, 1);
20 }
21
22 const char *tr2_cmd_name_get_hierarchy(void)
23 {
24         return tr2cmdname_hierarchy.buf;
25 }
26
27 void tr2_cmd_name_release(void)
28 {
29         strbuf_release(&tr2cmdname_hierarchy);
30 }