Merge branch 'js/unmap-before-ext-diff'
[git/git.git] / trace2 / tr2_cmd_name.c
CommitLineData
ee4512ed
JH
1#include "cache.h"
2#include "trace2/tr2_cmd_name.h"
3
e4b75d6a 4#define TR2_ENVVAR_PARENT_NAME "GIT_TRACE2_PARENT_NAME"
ee4512ed
JH
5
6static struct strbuf tr2cmdname_hierarchy = STRBUF_INIT;
7
8void 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
22const char *tr2_cmd_name_get_hierarchy(void)
23{
24 return tr2cmdname_hierarchy.buf;
25}
26
27void tr2_cmd_name_release(void)
28{
29 strbuf_release(&tr2cmdname_hierarchy);
30}