summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-07-13 17:11:19 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-07-13 17:11:19 +0200
commita58854a0311316a66fda363e83665ab942d81ec6 (patch)
treeeb12a3f0b1e99c55fb7f53eefdd48d5161eca928
parentf00f005bad3d27bb5c23ae5d7187622b940c5d0e (diff)
downloadlibgit2-cmn/submodule-backslash.tar.gz
submodule, path: extract slash conversioncmn/submodule-backslash
Extract the backslash-to-slash conversion into a helper function.
-rw-r--r--src/path.c16
-rw-r--r--src/path.h5
-rw-r--r--src/submodule.c10
3 files changed, 24 insertions, 7 deletions
diff --git a/src/path.c b/src/path.c
index 2558058dd..16283cab2 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1671,3 +1671,19 @@ bool git_path_isvalid(
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;
+}
diff --git a/src/path.h b/src/path.h
index 5927a5381..adb76865e 100644
--- a/src/path.h
+++ b/src/path.h
@@ -591,4 +591,9 @@ extern bool git_path_isvalid(
const char *path,
unsigned int flags);
+/**
+ * Convert any backslashes into slashes
+ */
+int git_path_normalize_slashes(git_buf *out, const char *path);
+
#endif
diff --git a/src/submodule.c b/src/submodule.c
index e4469efa3..f16d3c5ab 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -787,19 +787,15 @@ int git_submodule_resolve_url(git_buf *out, git_repository *repo, const char *ur
git_buf_sanitize(out);
+ /* We do this in all platforms in case someone on Windows created the .gitmodules */
if (strchr(url, '\\')) {
- char *p;
- if ((error = git_buf_puts(&normalized, url)) < 0)
+ if ((error = git_path_normalize_slashes(&normalized, url)) < 0)
return error;
- for (p = normalized.ptr; *p; p++) {
- if (*p == '\\')
- *p = '/';
- }
-
url = normalized.ptr;
}
+
if (git_path_is_relative(url)) {
if (!(error = get_url_base(out, repo)))
error = git_path_apply_relative(out, url);