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

Re: [PATCH] Set GIT_PATHNAME_PREFIX with aliases.

From
Jeff King <peff@peff.net>
Date
May 5, 2010, 00:51 UTC
Message-ID
<20100505005153.GC25390@coredump.intra.peff.net>
In-Reply-To
<1273019122.16093.6.camel@ubuntu.ubuntu-domain>
On Tue, May 04, 2010 at 08:25:22PM -0400, Jared Hance wrote:
Show 5 quoted lines
> The environment variable GIT_PATHNAME_PREFIX passes on the
> current working directory (where the git command was called from)
> to shell aliases (aliases that begin with "!"). This allows these
> shell aliases to know the directory that the git command was called
> from.
Seems like a reasonable goal, but...
Show 12 quoted lines
> --- a/git.c
> +++ b/git.c
> @@ -167,6 +167,9 @@ static int handle_alias(int *argcp, const char ***argv)
>  				free(alias_string);
>  				alias_string = buf.buf;
>  			}
> +			static char current_dir[PATH_MAX+1];
> +			setenv("GIT_PATHNAME_PREFIX", getcwd(current_dir, sizeof(current_dir)), 1);
> +
>  			trace_printf("trace: alias to shell cmd: %s => %s\n",
>  				     alias_command, alias_string + 1);
>  			ret = system(alias_string + 1);
I see three problems:
  1. Don't declare variables in the middle of a function. It's a C99-ism
     that we avoid to retain portability with older compilers.
  2. On getcwd error, we setenv the value to NULL. Is that OK on all
     platforms (I am specifically thinking of our Windows *env wrappers,
     which have some restrictions, but I don't remember the details)?
  3. Most importantly, isn't this totally the wrong place to look at
     getcwd? We're just about to run system(), which means we will
     already have done our chdir() (which probably is the one happening
     in setup_git_directory). On even a simple test, it seems to always
     print the root of the repository for me.
     I think instead you want to pass in the prefix value computed by
     setup_git_directory to handle_alias.
-Peff
Previous: Jared HanceNext: Johannes Sixt
Message 2 of 23 in “Set GIT_PATHNAME_PREFIX with aliases.”
  1. Set GIT_PATHNAME_PREFIX with aliases.Jared Hance, May 5, 2010
  2. Jeff KingMay 5, 2010
  3. Johannes SixtMay 5, 2010
  4. Jeff KingMay 5, 2010
  5. Eli BarzilayMay 5, 2010
  6. Junio C HamanoMay 5, 2010
  7. An alias that starts with "!!" runs in the current directory.Eli Barzilay, May 5, 2010
  8. Jared HanceMay 5, 2010
  9. Eli BarzilayMay 5, 2010
  10. Eli BarzilayMay 5, 2010
  11. Re-submitting patchesJonathan Nieder, May 5, 2010
  12. Eli BarzilayMay 5, 2010
  13. An alias that starts with "!!" runs in the current directory.Eli Barzilay, May 5, 2010
  14. Will PalmerMay 5, 2010
  15. Eli BarzilayMay 5, 2010
  16. Junio C HamanoMay 5, 2010
  17. Adam BrewsterMay 6, 2010
  18. Will PalmerMay 6, 2010
  19. Will PalmerMay 6, 2010
  20. Johannes SixtMay 6, 2010
  21. Matthieu MoyMay 6, 2010
  22. Junio C HamanoMay 5, 2010
  23. Eli BarzilayMay 5, 2010

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.