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

Re: [PATCH 2/3] run-command: teach locate_in_PATH about Windows

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 3, 2023, 16:13 UTC
Message-ID
<xmqq7cqc5cjf.fsf@gitster.g>
In-Reply-To
<bf8b34aaef32a64b85f778ab219aeb41238f2bf2.1691058498.git.gitgitgadget@gmail.com>

"Matthias Aßhauer via GitGitGadget" <gitgitgadget@gmail.com> writes:

Show 27 quoted lines
> diff --git a/run-command.c b/run-command.c
> index 60c94198664..8f518e37e27 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -182,13 +182,10 @@ int is_executable(const char *name)
>   * Returns the path to the command, as found in $PATH or NULL if the
>   * command could not be found.  The caller inherits ownership of the memory
>   * used to store the resultant path.
> - *
> - * This should not be used on Windows, where the $PATH search rules
> - * are more complicated (e.g., a search for "foo" should find
> - * "foo.exe").
>   */
>  static char *locate_in_PATH(const char *file)
>  {
> +#ifndef GIT_WINDOWS_NATIVE
>  	const char *p = getenv("PATH");
>  	struct strbuf buf = STRBUF_INIT;
>  
> @@ -217,6 +214,9 @@ static char *locate_in_PATH(const char *file)
>  
>  	strbuf_release(&buf);
>  	return NULL;
> +#else
> +	return mingw_path_lookup(file,0);
> +#endif
>  }
It may be cleaner to make the above more like
	#ifndef locate_in_PATH
	static char *locate_in_PATH(const char *file)
	{
	    ... original implementation without any #ifdef ...
	}
	#endif

and redo the [1/3] patch so that it does not rename or otherwise touch path_lookup() in any way, and instead implements a mingw_locate_in_PATH() in terms of path_lookup() and make it public, declare it in <compat/mingw.h>, together with #define locate_in_PATH(), i.e. [1/3] will essentially become something like:

    (add to compat/mingw.c)
    char *mingw_locate_in_PATH(const char *file)
    {
	return path_lookup(file, 0);
    }
    (add to compat/mingw.h)
    extern char *mingw_locate_in_PATH(const char *);
    #define locate_in_PATH(file) mingw_locate_in_PATH(file)

That way, the second non-UNIXy system can add its own way to locate an executable in PATH without having to touch the main part of the system, right?

Previous: Matthias Aßhauer via GitGitGadgetNext: Junio C Hamano
Message 6 of 23 in “git bisect visualize: find gitk on Windows again”
  1. 0/3 git bisect visualize: find gitk on Windows againMatthias Aßhauer via GitGitGadget, Aug 3, 2023
  2. 1/3 compat: make path_lookup() available outside mingw.cMatthias Aßhauer via GitGitGadget, Aug 3, 2023
  3. 3/3 docs: update when `git bisect visualize` uses `gitk`Matthias Aßhauer via GitGitGadget, Aug 3, 2023
  4. Junio C HamanoAug 3, 2023
  5. 2/3 run-command: teach locate_in_PATH about WindowsMatthias Aßhauer via GitGitGadget, Aug 3, 2023
  6. Junio C HamanoAug 3, 2023
  7. Junio C HamanoAug 3, 2023
  8. Junio C HamanoAug 3, 2023
  9. Matthias AßhauerAug 3, 2023
  10. Junio C HamanoAug 3, 2023
  11. 0/3 git bisect visualize: find gitk on Windows againMatthias Aßhauer via GitGitGadget, Aug 4, 2023
  12. 1/3 run-command: conditionally define locate_in_PATH()Matthias Aßhauer via GitGitGadget, Aug 4, 2023
  13. Junio C HamanoAug 4, 2023
  14. Matthias AßhauerAug 4, 2023
  15. Junio C HamanoAug 4, 2023
  16. 3/3 docs: update when `git bisect visualize` uses `gitk`Matthias Aßhauer via GitGitGadget, Aug 4, 2023
  17. Junio C HamanoAug 4, 2023
  18. Eric SunshineAug 4, 2023
  19. Matthias AßhauerAug 4, 2023
  20. Junio C HamanoAug 4, 2023
  21. Eric SunshineAug 4, 2023
  22. 2/3 compat/mingw: implement a native locate_in_PATH()Matthias Aßhauer via GitGitGadget, Aug 4, 2023
  23. Junio C HamanoAug 4, 2023

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.