зеркало из https://github.com/microsoft/git.git
GIT_TRACE: show which built-in/external commands are executed
With the environment variable GIT_TRACE set git will show - alias expansion - built-in command execution - external command execution on stderr. Signed-off-by: Matthias Lederhofer <matled@gmx.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Родитель
88f0d5d7d9
Коммит
575ba9d69d
|
@ -615,6 +615,13 @@ git Diffs
|
||||||
gitlink:git-diff-files[1];
|
gitlink:git-diff-files[1];
|
||||||
gitlink:git-diff-tree[1]
|
gitlink:git-diff-tree[1]
|
||||||
|
|
||||||
|
other
|
||||||
|
~~~~~
|
||||||
|
'GIT_TRACE'::
|
||||||
|
If this variable is set git will print `trace:` messages on
|
||||||
|
stderr telling about alias expansion, built-in command
|
||||||
|
execution and external command execution.
|
||||||
|
|
||||||
Discussion[[Discussion]]
|
Discussion[[Discussion]]
|
||||||
------------------------
|
------------------------
|
||||||
include::README[]
|
include::README[]
|
||||||
|
|
19
exec_cmd.c
19
exec_cmd.c
|
@ -1,5 +1,6 @@
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "exec_cmd.h"
|
#include "exec_cmd.h"
|
||||||
|
#include "quote.h"
|
||||||
#define MAX_ARGS 32
|
#define MAX_ARGS 32
|
||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
|
@ -96,9 +97,27 @@ int execv_git_cmd(const char **argv)
|
||||||
tmp = argv[0];
|
tmp = argv[0];
|
||||||
argv[0] = git_command;
|
argv[0] = git_command;
|
||||||
|
|
||||||
|
if (getenv("GIT_TRACE")) {
|
||||||
|
fputs("trace: exec:", stderr);
|
||||||
|
const char **p = argv;
|
||||||
|
while (*p) {
|
||||||
|
fputc(' ', stderr);
|
||||||
|
sq_quote_print(stderr, *p);
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
putc('\n', stderr);
|
||||||
|
fflush(stderr);
|
||||||
|
}
|
||||||
|
|
||||||
/* execve() can only ever return if it fails */
|
/* execve() can only ever return if it fails */
|
||||||
execve(git_command, (char **)argv, environ);
|
execve(git_command, (char **)argv, environ);
|
||||||
|
|
||||||
|
if (getenv("GIT_TRACE")) {
|
||||||
|
fprintf(stderr, "trace: exec failed: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
fflush(stderr);
|
||||||
|
}
|
||||||
|
|
||||||
argv[0] = tmp;
|
argv[0] = tmp;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|
25
git.c
25
git.c
|
@ -11,6 +11,7 @@
|
||||||
#include "git-compat-util.h"
|
#include "git-compat-util.h"
|
||||||
#include "exec_cmd.h"
|
#include "exec_cmd.h"
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
#include "quote.h"
|
||||||
|
|
||||||
#include "builtin.h"
|
#include "builtin.h"
|
||||||
|
|
||||||
|
@ -120,6 +121,18 @@ static int handle_alias(int *argcp, const char ***argv)
|
||||||
if (!strcmp(alias_command, new_argv[0]))
|
if (!strcmp(alias_command, new_argv[0]))
|
||||||
die("recursive alias: %s", alias_command);
|
die("recursive alias: %s", alias_command);
|
||||||
|
|
||||||
|
if (getenv("GIT_TRACE")) {
|
||||||
|
int i;
|
||||||
|
fprintf(stderr, "trace: alias expansion: %s =>",
|
||||||
|
alias_command);
|
||||||
|
for (i = 0; i < count; ++i) {
|
||||||
|
fputc(' ', stderr);
|
||||||
|
sq_quote_print(stderr, new_argv[i]);
|
||||||
|
}
|
||||||
|
fputc('\n', stderr);
|
||||||
|
fflush(stderr);
|
||||||
|
}
|
||||||
|
|
||||||
/* insert after command name */
|
/* insert after command name */
|
||||||
if (*argcp > 1) {
|
if (*argcp > 1) {
|
||||||
new_argv = realloc(new_argv, sizeof(char*) *
|
new_argv = realloc(new_argv, sizeof(char*) *
|
||||||
|
@ -202,6 +215,18 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
|
||||||
struct cmd_struct *p = commands+i;
|
struct cmd_struct *p = commands+i;
|
||||||
if (strcmp(p->cmd, cmd))
|
if (strcmp(p->cmd, cmd))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (getenv("GIT_TRACE")) {
|
||||||
|
int i;
|
||||||
|
fprintf(stderr, "trace: built-in: git");
|
||||||
|
for (i = 0; i < argc; ++i) {
|
||||||
|
fputc(' ', stderr);
|
||||||
|
sq_quote_print(stderr, argv[i]);
|
||||||
|
}
|
||||||
|
putc('\n', stderr);
|
||||||
|
fflush(stderr);
|
||||||
|
}
|
||||||
|
|
||||||
exit(p->fn(argc, argv, envp));
|
exit(p->fn(argc, argv, envp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
quote.c
17
quote.c
|
@ -45,6 +45,23 @@ size_t sq_quote_buf(char *dst, size_t n, const char *src)
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sq_quote_print(FILE *stream, const char *src)
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
|
||||||
|
fputc('\'', stream);
|
||||||
|
while ((c = *src++)) {
|
||||||
|
if (need_bs_quote(c)) {
|
||||||
|
fputs("'\\", stream);
|
||||||
|
fputc(c, stream);
|
||||||
|
fputc('\'', stream);
|
||||||
|
} else {
|
||||||
|
fputc(c, stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fputc('\'', stream);
|
||||||
|
}
|
||||||
|
|
||||||
char *sq_quote(const char *src)
|
char *sq_quote(const char *src)
|
||||||
{
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
1
quote.h
1
quote.h
|
@ -29,6 +29,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern char *sq_quote(const char *src);
|
extern char *sq_quote(const char *src);
|
||||||
|
extern void sq_quote_print(FILE *stream, const char *src);
|
||||||
extern size_t sq_quote_buf(char *dst, size_t n, const char *src);
|
extern size_t sq_quote_buf(char *dst, size_t n, const char *src);
|
||||||
|
|
||||||
/* This unwraps what sq_quote() produces in place, but returns
|
/* This unwraps what sq_quote() produces in place, but returns
|
||||||
|
|
Загрузка…
Ссылка в новой задаче