All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Mohit Marathe via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Mohit Marathe <mohitmarathe@proton.me>,
	Mohit Marathe <mohitmarathe@proton.me>
Subject: [PATCH 1/2] git-compat-util: migrate `convert_slashes()` from compat/mingw.h
Date: Mon, 18 Mar 2024 12:47:41 +0000	[thread overview]
Message-ID: <0157b1deaebd5de4734d35f96f22a8da752e09bd.1710766062.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1699.git.1710766062.gitgitgadget@gmail.com>

From: Mohit Marathe <mohitmarathe@proton.me>

This patch migrates the `convert_slashes` function to `git-compat-
util.h` and renames it to `change_path_separators`.

Signed-off-by: Mohit Marathe <mohitmarathe@proton.me>
---
 abspath.c         | 4 ++--
 compat/mingw.c    | 4 ++--
 compat/mingw.h    | 6 ------
 git-compat-util.h | 7 +++++++
 path.c            | 2 +-
 5 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/abspath.c b/abspath.c
index 1202cde23db..ea35e2c05ce 100644
--- a/abspath.c
+++ b/abspath.c
@@ -58,7 +58,7 @@ static void get_root_part(struct strbuf *resolved, struct strbuf *remaining)
 	strbuf_reset(resolved);
 	strbuf_add(resolved, remaining->buf, offset);
 #ifdef GIT_WINDOWS_NATIVE
-	convert_slashes(resolved->buf);
+	change_path_separators(resolved->buf);
 #endif
 	strbuf_remove(remaining, 0, offset);
 }
@@ -278,7 +278,7 @@ char *prefix_filename(const char *pfx, const char *arg)
 
 	strbuf_addstr(&path, arg);
 #ifdef GIT_WINDOWS_NATIVE
-	convert_slashes(path.buf + pfx_len);
+	change_path_separators(path.buf + pfx_len);
 #endif
 	return strbuf_detach(&path, NULL);
 }
diff --git a/compat/mingw.c b/compat/mingw.c
index 320fb99a90e..f7c1a009563 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1170,7 +1170,7 @@ char *mingw_getcwd(char *pointer, int len)
 	}
 	if (xwcstoutf(pointer, wpointer, len) < 0)
 		return NULL;
-	convert_slashes(pointer);
+	change_path_separators(pointer);
 	return pointer;
 }
 
@@ -2636,7 +2636,7 @@ static void setup_windows_environment(void)
 		 * executable (by not mistaking the dir separators
 		 * for escape characters).
 		 */
-		convert_slashes(tmp);
+		change_path_separators(tmp);
 	}
 
 	/* simulate TERM to enable auto-color (see color.c) */
diff --git a/compat/mingw.h b/compat/mingw.h
index 6aec50e4124..f5ca4adc194 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -448,12 +448,6 @@ HANDLE winansi_get_osfhandle(int fd);
  * git specific compatibility
  */
 
-static inline void convert_slashes(char *path)
-{
-	for (; *path; path++)
-		if (*path == '\\')
-			*path = '/';
-}
 #define PATH_SEP ';'
 char *mingw_query_user_email(void);
 #define query_user_email mingw_query_user_email
diff --git a/git-compat-util.h b/git-compat-util.h
index 7c2a6538e5a..3db90c09295 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -1309,6 +1309,13 @@ static inline int strtol_i(char const *s, int base, int *result)
 	return 0;
 }
 
+static inline void change_path_separators(char *path)
+{
+	for (; *path; path++)
+		if (*path == '\\')
+			*path = '/';
+}
+
 void git_stable_qsort(void *base, size_t nmemb, size_t size,
 		      int(*compar)(const void *, const void *));
 #ifdef INTERNAL_QSORT
diff --git a/path.c b/path.c
index 8bb223c92c9..cd7c88ffa0d 100644
--- a/path.c
+++ b/path.c
@@ -758,7 +758,7 @@ char *interpolate_path(const char *path, int real_home)
 			else
 				strbuf_addstr(&user_path, home);
 #ifdef GIT_WINDOWS_NATIVE
-			convert_slashes(user_path.buf);
+			change_path_separators(user_path.buf);
 #endif
 		} else {
 			struct passwd *pw = getpw_str(username, username_len);
-- 
gitgitgadget


  reply	other threads:[~2024-03-18 12:47 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 ` Mohit Marathe via GitGitGadget [this message]
2024-03-18 21:57   ` [PATCH 1/2] git-compat-util: migrate `convert_slashes()` from compat/mingw.h 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
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

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

  git send-email \
    --in-reply-to=0157b1deaebd5de4734d35f96f22a8da752e09bd.1710766062.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.