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

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

From
Mohit Marathe via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 18, 2024, 12:47 UTC
Message-ID
<8a730b6ebba4111aaad4e8fc938c52f6e7e54480.1710766062.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1699.git.1710766062.gitgitgadget@gmail.com>
From: Mohit Marathe <mohitmarathe@proton.me>

This patch replaces the code, that changes the path separators, with the already existing function `change_path_separators()`

Signed-off-by: Mohit Marathe <mohitmarathe@proton.me>
---
 t/unit-tests/test-lib.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/t/unit-tests/test-lib.c b/t/unit-tests/test-lib.c
index 66d6980ffbe..b0e26263046 100644
--- a/t/unit-tests/test-lib.c
+++ b/t/unit-tests/test-lib.c
@@ -52,9 +52,7 @@ static const char *make_relative(const char *location)
 		prefix_len = len - needle_len;
 		if (prefix[prefix_len + 1] == '/') {
 			/* Oh, we're not Windows */
-			for (size_t i = 0; i < needle_len; i++)
-				if (needle[i] == '\\')
-					needle[i] = '/';
+			change_path_separators(&needle[0]);
 			need_bs_to_fs = 0;
 		} else {
 			need_bs_to_fs = 1;
@@ -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;
 }
 
-- 
gitgitgadget
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 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.