git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Mohit Marathe via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,  Mohit Marathe <mohitmarathe@proton.me>
Subject: Re: [PATCH 2/2] test-lib: replace repeated code logic with an existing helper
Date: Mon, 18 Mar 2024 14:58:57 -0700	[thread overview]
Message-ID: <xmqq7chzdwwu.fsf@gitster.g> (raw)
In-Reply-To: <8a730b6ebba4111aaad4e8fc938c52f6e7e54480.1710766062.git.gitgitgadget@gmail.com> (Mohit Marathe via GitGitGadget's message of "Mon, 18 Mar 2024 12:47:42 +0000")

"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.

> @@ -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;
>  }


  reply	other threads:[~2024-03-18 21:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-18 12:47 [PATCH 0/2] git-compat-util: move convert_slashes from compat/mingw.h and rename it Mohit Marathe via GitGitGadget
2024-03-18 12:47 ` [PATCH 1/2] git-compat-util: migrate `convert_slashes()` from compat/mingw.h Mohit Marathe via GitGitGadget
2024-03-18 21:57   ` Junio C Hamano
2024-03-18 12:47 ` [PATCH 2/2] test-lib: replace repeated code logic with an existing helper Mohit Marathe via GitGitGadget
2024-03-18 21:58   ` Junio C Hamano [this message]
2024-04-11 21:42   ` Josh Steadmon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq7chzdwwu.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=mohitmarathe@proton.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).