forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
git-compat-util: move convert_slashes
from compat/mingw.h and rename it
#1699
Open
mohit-marathe
wants to merge
2
commits into
gitgitgadget:master
Choose a base branch
from
mohit-marathe:convert-slashes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,9 +52,7 @@ static const char *make_relative(const char *location) | |
prefix_len = len - needle_len; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this): "Mohit Marathe via GitGitGadget" <[email protected]> writes:
> From: Mohit Marathe <[email protected]>
>
> 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;
> } There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Josh Steadmon wrote (reply to this): On 2024.03.18 12:47, Mohit Marathe via GitGitGadget wrote:
> From: Mohit Marathe <[email protected]>
>
> This patch replaces the code, that changes the path separators,
> with the already existing function `change_path_separators()`
>
> Signed-off-by: Mohit Marathe <[email protected]>
> ---
> 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]);
Why not just:
change_path_separators(needle);
?
> 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);
And here, why not:
change_path_separators(buf)
?
> return buf;
> }
>
> --
> gitgitgadget
> |
||
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; | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Git mailing list, Junio C Hamano wrote (reply to this):