Skip to content

Commit

Permalink
trace2: move 'def_param' events into 'cmd_name' and 'cmd_alias'
Browse files Browse the repository at this point in the history
Some Git commands do not emit `def_param` events for interesting
config and environment variable settings.  Let's fix that.

Builtin commands compiled into `git.c` have the normal control flow
and emit a `cmd_name` event and then `def_param` events for each
interesting config and environment variable.  However, some special
"query" commands, like `--exec-path`, or some forms of alias
expansion, emitted a `cmd_name` but did not emit `def_param` events.

Also, special commands `git-remote-https` is built from `remote-curl.c`
and `git-http-fetch` is built from `http-fetch.c` and do not use
the normal set up in `git.c`.  These emitted a `cmd_name` but not
`def_param` events.

To minimize the footprint of this commit, move the calls to
`trace2_cmd_list_config()` and `trace2_cmd_list_env_vars()` into
`trace2_cmd_name()` and `trace2_cmd_alias()` so that we always
get a set `def_param` events when a `cmd_name` or `cmd_alias`
event is generated.

Signed-off-by: Jeff Hostetler <[email protected]>
  • Loading branch information
jeffhostetler committed Feb 29, 2024
1 parent 0f9d4d2 commit 8967b38
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 0 additions & 6 deletions git.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,6 @@ static int handle_alias(int *argcp, const char ***argv)
strvec_pushv(&child.args, (*argv) + 1);

trace2_cmd_alias(alias_command, child.args.v);
trace2_cmd_list_config();
trace2_cmd_list_env_vars();
trace2_cmd_name("_run_shell_alias_");

ret = run_command(&child);
Expand Down Expand Up @@ -411,8 +409,6 @@ static int handle_alias(int *argcp, const char ***argv)
COPY_ARRAY(new_argv + count, *argv + 1, *argcp);

trace2_cmd_alias(alias_command, new_argv);
trace2_cmd_list_config();
trace2_cmd_list_env_vars();

*argv = new_argv;
*argcp += count - 1;
Expand Down Expand Up @@ -462,8 +458,6 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)

trace_argv_printf(argv, "trace: built-in: git");
trace2_cmd_name(p->cmd);
trace2_cmd_list_config();
trace2_cmd_list_env_vars();

validate_cache_entries(the_repository->index);
status = p->fn(argc, argv, prefix);
Expand Down
2 changes: 0 additions & 2 deletions t/helper/test-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ int cmd_main(int argc, const char **argv)
argv++;
argc--;
trace2_cmd_name(cmds[i].name);
trace2_cmd_list_config();
trace2_cmd_list_env_vars();
return cmds[i].fn(argc, argv);
}
}
Expand Down
18 changes: 18 additions & 0 deletions trace2.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ void trace2_cmd_name_fl(const char *file, int line, const char *name)
for_each_wanted_builtin (j, tgt_j)
if (tgt_j->pfn_command_name_fl)
tgt_j->pfn_command_name_fl(file, line, name, hierarchy);

trace2_cmd_list_config();
trace2_cmd_list_env_vars();
}

void trace2_cmd_mode_fl(const char *file, int line, const char *mode)
Expand Down Expand Up @@ -460,21 +463,36 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,
for_each_wanted_builtin (j, tgt_j)
if (tgt_j->pfn_alias_fl)
tgt_j->pfn_alias_fl(file, line, alias, argv);

trace2_cmd_list_config();
trace2_cmd_list_env_vars();
}

void trace2_cmd_list_config_fl(const char *file, int line)
{
static int printed = 0;

if (!trace2_enabled)
return;

if (printed)
return;
printed = 1;

tr2_cfg_list_config_fl(file, line);
}

void trace2_cmd_list_env_vars_fl(const char *file, int line)
{
static int printed = 0;

if (!trace2_enabled)
return;

if (printed)
return;
printed = 1;

tr2_list_env_vars_fl(file, line);
}

Expand Down

0 comments on commit 8967b38

Please sign in to comment.