mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-08 15:24:11 +00:00
submodule, path: extract slash conversion
Extract the backslash-to-slash conversion into a helper function.
This commit is contained in:
parent
f00f005bad
commit
a58854a031
16
src/path.c
16
src/path.c
@ -1671,3 +1671,19 @@ bool git_path_isvalid(
|
|||||||
|
|
||||||
return verify_component(repo, start, (c - start), flags);
|
return verify_component(repo, start, (c - start), flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int git_path_normalize_slashes(git_buf *out, const char *path)
|
||||||
|
{
|
||||||
|
int error;
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
if ((error = git_buf_puts(out, path)) < 0)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
for (p = out->ptr; *p; p++) {
|
||||||
|
if (*p == '\\')
|
||||||
|
*p = '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -591,4 +591,9 @@ extern bool git_path_isvalid(
|
|||||||
const char *path,
|
const char *path,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert any backslashes into slashes
|
||||||
|
*/
|
||||||
|
int git_path_normalize_slashes(git_buf *out, const char *path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -787,19 +787,15 @@ int git_submodule_resolve_url(git_buf *out, git_repository *repo, const char *ur
|
|||||||
|
|
||||||
git_buf_sanitize(out);
|
git_buf_sanitize(out);
|
||||||
|
|
||||||
|
/* We do this in all platforms in case someone on Windows created the .gitmodules */
|
||||||
if (strchr(url, '\\')) {
|
if (strchr(url, '\\')) {
|
||||||
char *p;
|
if ((error = git_path_normalize_slashes(&normalized, url)) < 0)
|
||||||
if ((error = git_buf_puts(&normalized, url)) < 0)
|
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
for (p = normalized.ptr; *p; p++) {
|
|
||||||
if (*p == '\\')
|
|
||||||
*p = '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
url = normalized.ptr;
|
url = normalized.ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (git_path_is_relative(url)) {
|
if (git_path_is_relative(url)) {
|
||||||
if (!(error = get_url_base(out, repo)))
|
if (!(error = get_url_base(out, repo)))
|
||||||
error = git_path_apply_relative(out, url);
|
error = git_path_apply_relative(out, url);
|
||||||
|
Loading…
Reference in New Issue
Block a user