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

Re: [PATCH 2/2] test-lib: replace repeated code logic with an existing helper

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 18, 2024, 21:58 UTC
Message-ID
<xmqq7chzdwwu.fsf@gitster.g>
In-Reply-To
<8a730b6ebba4111aaad4e8fc938c52f6e7e54480.1710766062.git.gitgitgadget@gmail.com>
"Mohit Marathe via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Mohit Marathe <mohitmarathe@proton.me>
>
> This patch replaces the code, that changes the path separators,
> with the already existing function `change_path_separators()`

Aside from that the name change_path_separators() needs to be updated, using it here means that the helper cannot become a NO-OP on platforms where we do not have to change backslashes we read from the system to forward slashes. So if we really wanted to use it here, and update the other existing callers in the main code to help them lose the ugly "#if WINDOWS" conditional compilation, we would need two helper functions, perhaps one that is used here that is identical to the current convert_slashes(), and the other one used to clean-up the callsites in [1/2] to also remove the conditional compilation.

Even if we were to make it public, I am not sure if compat-util is the right place, though. It is not a kitchen sink.

In any case, perhaps we want to do something like this in a header, ...

	static inline void bs_to_forward_slash_in_place(char *path)
	{
		...
	}
	#ifdef GIT_WINDOWS_NATIVE
	#define normalize_slashes_in_place(path) bs_to_forward_slash_in_place(path)
	#else
	#define normalize_slashes_in_place(path) do { ; /* nothing */ } while (0)
	#endif

... and then use the "normalize" one to lose "#ifdef" in the callers [1/2] touches, while "bs_to_forward_slash" one here.

I am not convinced if it is worth doing only for this single test, though.

Show 11 quoted lines
> @@ -88,9 +86,8 @@ static const char *make_relative(const char *location)
>  
>  	/* convert backslashes to forward slashes */
>  	strlcpy(buf, location + prefix_len, sizeof(buf));
> -	for (p = buf; *p; p++)
> -		if (*p == '\\')
> -			*p = '/';
> +	p = buf;
> +	change_path_separators(p);
>  	return buf;
>  }
Previous: Mohit Marathe via GitGitGadgetNext: Josh Steadmon
Message 5 of 6 in “git-compat-util: move convert_slashes from compat/mingw.h and rename it”
  1. 0/2 git-compat-util: move convert_slashes from compat/mingw.h and rename itMohit Marathe via GitGitGadget, Mar 18, 2024
  2. 1/2 git-compat-util: migrate `convert_slashes()` from compat/mingw.hMohit Marathe via GitGitGadget, Mar 18, 2024
  3. Junio C HamanoMar 18, 2024
  4. 2/2 test-lib: replace repeated code logic with an existing helperMohit Marathe via GitGitGadget, Mar 18, 2024
  5. Junio C HamanoMar 18, 2024
  6. Josh SteadmonApr 11, 2024

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.