git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Tracing commands includes its working directory

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 14, 2015, 21:45 UTC
Message-ID
<xmqqbnc16s58.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1444857857-25796-1-git-send-email-sbeller@google.com>
Stefan Beller <sbeller@google.com> writes:
Show 7 quoted lines
> Specially when having concurrent flows of command execution,
> the order of commands printed cannot be relied upon. To aid
> the poor developer follow the flow of commands include the
> current working directory in which the command is carried out.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---

I am not quite sure about the motivation behind this patch. If you are doing N processes, each of which *happens* to be working inside its own directory that is different from all others, then it may be a usable way to tell them apart, but that smells like too much of special casing that will be applicable ohly to what you happen to be developing recently and nowhere else. Some of these N processes share the same cwd in an application different from yours.

One way to tweak it to be generic enough may be to show a trace output when git goes into a different working directory, which is a significant event that is worth tracing, and then have a mode where all trace lines are prefixed with process ID, perhaps?

Show 73 quoted lines
>  exec_cmd.c    | 2 +-
>  git.c         | 8 ++++----
>  run-command.c | 4 ++--
>  3 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/exec_cmd.c b/exec_cmd.c
> index e85f0fd..bb79933 100644
> --- a/exec_cmd.c
> +++ b/exec_cmd.c
> @@ -125,7 +125,7 @@ const char **prepare_git_cmd(const char **argv)
>  
>  int execv_git_cmd(const char **argv) {
>  	const char **nargv = prepare_git_cmd(argv);
> -	trace_argv_printf(nargv, "trace: exec:");
> +	trace_argv_printf(nargv, "(%s) trace: exec:", xgetcwd());
>  
>  	/* execvp() can only ever return if it fails */
>  	sane_execvp("git", (char **)nargv);
> diff --git a/git.c b/git.c
> index deecba0..e077e2d 100644
> --- a/git.c
> +++ b/git.c
> @@ -278,8 +278,8 @@ static int handle_alias(int *argcp, const char ***argv)
>  			die("recursive alias: %s", alias_command);
>  
>  		trace_argv_printf(new_argv,
> -				  "trace: alias expansion: %s =>",
> -				  alias_command);
> +				  "(%s) trace: alias expansion: %s =>",
> +				  xgetcwd(), alias_command);
>  
>  		REALLOC_ARRAY(new_argv, count + *argcp);
>  		/* insert after command name */
> @@ -345,7 +345,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
>  	if (!help && p->option & NEED_WORK_TREE)
>  		setup_work_tree();
>  
> -	trace_argv_printf(argv, "trace: built-in: git");
> +	trace_argv_printf(argv, "(%s) trace: built-in: git", xgetcwd());
>  
>  	status = p->fn(argc, argv, prefix);
>  	if (status)
> @@ -557,7 +557,7 @@ static void execv_dashed_external(const char **argv)
>  	tmp = argv[0];
>  	argv[0] = cmd.buf;
>  
> -	trace_argv_printf(argv, "trace: exec:");
> +	trace_argv_printf(argv, "(%s) trace: exec:", xgetcwd());
>  
>  	/*
>  	 * if we fail because the command is not found, it is
> diff --git a/run-command.c b/run-command.c
> index ef3da27..e483bae 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -194,7 +194,7 @@ static const char **prepare_shell_cmd(const char **argv)
>  static int execv_shell_cmd(const char **argv)
>  {
>  	const char **nargv = prepare_shell_cmd(argv);
> -	trace_argv_printf(nargv, "trace: exec:");
> +	trace_argv_printf(nargv, "(%s) trace: exec:", xgetcwd());
>  	sane_execvp(nargv[0], (char **)nargv);
>  	free(nargv);
>  	return -1;
> @@ -346,7 +346,7 @@ fail_pipe:
>  		cmd->err = fderr[0];
>  	}
>  
> -	trace_argv_printf(cmd->argv, "trace: run_command:");
> +	trace_argv_printf(cmd->argv, "(%s) trace: run_command:", xgetcwd());
>  	fflush(NULL);
>  
>  #ifndef GIT_WINDOWS_NATIVE
Previous: Stefan Beller
Message 2 of 2 in “Tracing commands includes its working directory”
  1. Tracing commands includes its working directoryStefan Beller, Oct 14, 2015
  2. Junio C HamanoOct 14, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.