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

Re: [PATCH 1/4] config --show-origin: report paths with forward slashes

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 4, 2016, 15:51 UTC
Message-ID
<xmqqd1q574p8.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<57001772.7090007@kdbg.org>
Johannes Sixt <j6t@kdbg.org> writes:
Show 7 quoted lines
> Although I am convinced that the change is not necessary for
> correctness, I can buy the justification that we should produce forward
> slashes for consistency. There are a number of occasions where we
> present paths to the user, and we do show forward-slashes in all cases
> that I found. We should keep the commit.
>
> But then let's do this:

Sounds like a plan; even though I am mildly against adding more platform specific #ifdef to files outside compat/, this patch does not.

Dscho?
Show 68 quoted lines
>
> ---- 8< ----
> Subject: [PATCH] Windows: shorten code by re-using convert_slashes()
>
> Make a few more spots more readable by using the recently introduced,
> Windows-specific helper.
>
> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
> ---
>  abspath.c      | 5 +----
>  compat/mingw.c | 9 ++-------
>  2 files changed, 3 insertions(+), 11 deletions(-)
>
> diff --git a/abspath.c b/abspath.c
> index 5edb4e7..2825de8 100644
> --- a/abspath.c
> +++ b/abspath.c
> @@ -167,7 +167,6 @@ const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
>  	strbuf_add(&path, pfx, pfx_len);
>  	strbuf_addstr(&path, arg);
>  #else
> -	char *p;
>  	/* don't add prefix to absolute paths, but still replace '\' by '/' */
>  	strbuf_reset(&path);
>  	if (is_absolute_path(arg))
> @@ -175,9 +174,7 @@ const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
>  	else if (pfx_len)
>  		strbuf_add(&path, pfx, pfx_len);
>  	strbuf_addstr(&path, arg);
> -	for (p = path.buf + pfx_len; *p; p++)
> -		if (*p == '\\')
> -			*p = '/';
> +	convert_slashes(path.buf + pfx_len);
>  #endif
>  	return path.buf;
>  }
> diff --git a/compat/mingw.c b/compat/mingw.c
> index 54c82ec..0413d5c 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -763,15 +763,12 @@ struct tm *localtime_r(const time_t *timep, struct tm *result)
>  
>  char *mingw_getcwd(char *pointer, int len)
>  {
> -	int i;
>  	wchar_t wpointer[MAX_PATH];
>  	if (!_wgetcwd(wpointer, ARRAY_SIZE(wpointer)))
>  		return NULL;
>  	if (xwcstoutf(pointer, wpointer, len) < 0)
>  		return NULL;
> -	for (i = 0; pointer[i]; i++)
> -		if (pointer[i] == '\\')
> -			pointer[i] = '/';
> +	convert_slashes(pointer);
>  	return pointer;
>  }
>  
> @@ -2112,9 +2109,7 @@ static void setup_windows_environment()
>  		 * executable (by not mistaking the dir separators
>  		 * for escape characters).
>  		 */
> -		for (; *tmp; tmp++)
> -			if (*tmp == '\\')
> -				*tmp = '/';
> +		convert_slashes(tmp);
>  	}
>  
>  	/* simulate TERM to enable auto-color (see color.c) */
Previous: Johannes SixtNext: Johannes Schindelin
Message 11 of 42 in “Git for Windows fixes in preparation for 2.8.0”
  1. 0/4 Git for Windows fixes in preparation for 2.8.0Johannes Schindelin, Mar 22, 2016
  2. 1/4 config --show-origin: report paths with forward slashesJohannes Schindelin, Mar 22, 2016
  3. Junio C HamanoMar 22, 2016
  4. Johannes SchindelinMar 23, 2016
  5. Junio C HamanoMar 23, 2016
  6. Johannes SixtMar 28, 2016
  7. Johannes SchindelinMar 28, 2016
  8. Johannes SixtMar 29, 2016
  9. Junio C HamanoMar 29, 2016
  10. Johannes SixtApr 2, 2016
  11. Junio C HamanoApr 4, 2016
  12. Johannes SchindelinApr 4, 2016
  13. Johannes SixtMar 30, 2016
  14. Johannes SixtApr 2, 2016
  15. 2/4 Make t1300-repo-config resilient to being run via 'sh -x'Johannes Schindelin, Mar 22, 2016
  16. Jonathan NiederMar 22, 2016
  17. Junio C HamanoMar 22, 2016
  18. Jonathan NiederMar 22, 2016
  19. Johannes SchindelinMar 23, 2016
  20. Junio C HamanoMar 22, 2016
  21. Johannes SchindelinMar 23, 2016
  22. 3/4 t1300: fix the new --show-origin tests on WindowsJohannes Schindelin, Mar 22, 2016
  23. Junio C HamanoMar 22, 2016
  24. Johannes SchindelinMar 23, 2016
  25. 4/4 mingw: skip some tests in t9115 due to file name issuesJohannes Schindelin, Mar 22, 2016
  26. Jonathan NiederMar 22, 2016
  27. Torsten BögershausenMar 22, 2016
  28. Junio C HamanoMar 22, 2016
  29. Torsten BögershausenMar 22, 2016
  30. Junio C HamanoMar 22, 2016
  31. Torsten BögershausenMar 23, 2016
  32. Johannes SchindelinMar 23, 2016
  33. Junio C HamanoMar 23, 2016
  34. Torsten BögershausenMar 23, 2016
  35. Torsten BögershausenMar 23, 2016
  36. Junio C HamanoMar 22, 2016
  37. 0/4 Git for Windows fixes in preparation for 2.8.0Johannes Schindelin, Mar 23, 2016
  38. 1/4 config --show-origin: report paths with forward slashesJohannes Schindelin, Mar 23, 2016
  39. 2/4 Make t1300-repo-config resilient to being run via 'sh -x'Johannes Schindelin, Mar 23, 2016
  40. 3/4 t1300: fix the new --show-origin tests on WindowsJohannes Schindelin, Mar 23, 2016
  41. Lars SchneiderMar 23, 2016
  42. 4/4 mingw: skip some tests in t9115 due to file name issuesJohannes Schindelin, Mar 23, 2016

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.