|
29 | 29 | #include "quote.h" |
30 | 30 | #include "setup.h" |
31 | 31 | #include "trace.h" |
| 32 | +#include "strvec.h" |
| 33 | +#include "config.h" |
32 | 34 |
|
33 | 35 | struct trace_key trace_default_key = { "GIT_TRACE", 0, 0, 0 }; |
34 | 36 | struct trace_key trace_perf_key = TRACE_KEY_INIT(PERFORMANCE); |
@@ -442,3 +444,47 @@ void trace_command_performance(const char **argv) |
442 | 444 | sq_quote_argv_pretty(&command_line, argv); |
443 | 445 | trace_performance_enter(); |
444 | 446 | } |
| 447 | + |
| 448 | +struct trace_config_data { |
| 449 | + const char *want_cmd; |
| 450 | + struct strvec *out; |
| 451 | +}; |
| 452 | + |
| 453 | +static int trace_config_cb(const char *var, const char *value, |
| 454 | + const struct config_context *ctx UNUSED, void *vdata) |
| 455 | +{ |
| 456 | + struct trace_config_data *data = vdata; |
| 457 | + const char *have_cmd, *key; |
| 458 | + size_t have_len; |
| 459 | + |
| 460 | + if (!parse_config_key(var, "trace", &have_cmd, &have_len, &key) && |
| 461 | + have_cmd && |
| 462 | + !strncmp(data->want_cmd, have_cmd, have_len) && |
| 463 | + data->want_cmd[have_len] == '\0') { |
| 464 | + struct strbuf buf = STRBUF_INIT; |
| 465 | + |
| 466 | + strbuf_addstr(&buf, "GIT_TRACE_"); |
| 467 | + while (*key) |
| 468 | + strbuf_addch(&buf, toupper(*key++)); |
| 469 | + |
| 470 | + /* |
| 471 | + * Environment always takes precedence over config, so do not |
| 472 | + * override existing variables. We cannot rely on setenv()'s |
| 473 | + * overwrite flag here, because we may pass the list off to |
| 474 | + * a spawn() implementation, which always overwrites. |
| 475 | + */ |
| 476 | + if (!getenv(buf.buf)) |
| 477 | + strvec_pushf(data->out, "%s=%s", buf.buf, value); |
| 478 | + |
| 479 | + strbuf_release(&buf); |
| 480 | + } |
| 481 | + return 0; |
| 482 | +} |
| 483 | + |
| 484 | +void trace_config_for(struct repository *r, const char *cmd, struct strvec *out) |
| 485 | +{ |
| 486 | + struct trace_config_data data; |
| 487 | + data.want_cmd = cmd; |
| 488 | + data.out = out; |
| 489 | + repo_config(r, trace_config_cb, &data); |
| 490 | +} |
0 commit comments