Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Niessink <theo@taletn.com>2011-05-27 20:00:39 +0400
committerJunio C Hamano <gitster@pobox.com>2011-05-27 21:59:16 +0400
commitd1c69255a1014ccaeb9841f2114e20f048556391 (patch)
treecf14af796f23230e0f2cbda339e4bc7074c1c7d1
parent88135203af9df27c0f9c76c27bbbf48833bb31c8 (diff)
real_path: do not assume '/' is the path seperator
real_path currently assumes it's input had '/' as path seperator. This assumption does not hold true for the code-path from prefix_path (on Windows), where real_path can be called before normalize_path_copy. Fix real_path so it doesn't make this assumption. Create a helper function to reverse-search for the last path-seperator in a string. Signed-off-by: Theo Niessink <theo@taletn.com> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--abspath.c4
-rw-r--r--compat/mingw.h9
-rw-r--r--git-compat-util.h4
3 files changed, 15 insertions, 2 deletions
diff --git a/abspath.c b/abspath.c
index ff140689ed..54899008f8 100644
--- a/abspath.c
+++ b/abspath.c
@@ -33,7 +33,7 @@ const char *make_absolute_path(const char *path)
while (depth--) {
if (!is_directory(buf)) {
- char *last_slash = strrchr(buf, '/');
+ char *last_slash = find_last_dir_sep(buf);
if (last_slash) {
*last_slash = '\0';
last_elem = xstrdup(last_slash + 1);
@@ -58,7 +58,7 @@ const char *make_absolute_path(const char *path)
if (len + strlen(last_elem) + 2 > PATH_MAX)
die ("Too long path name: '%s/%s'",
buf, last_elem);
- if (len && buf[len-1] != '/')
+ if (len && !is_dir_sep(buf[len-1]))
buf[len++] = '/';
strcpy(buf + len, last_elem);
free(last_elem);
diff --git a/compat/mingw.h b/compat/mingw.h
index 14211c6214..bea909d76f 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -299,6 +299,15 @@ int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format
#define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
#define is_dir_sep(c) ((c) == '/' || (c) == '\\')
+static inline char *mingw_find_last_dir_sep(const char *path)
+{
+ char *ret = NULL;
+ for (; *path; ++path)
+ if (is_dir_sep(*path))
+ ret = (char *)path;
+ return ret;
+}
+#define find_last_dir_sep mingw_find_last_dir_sep
#define PATH_SEP ';'
#define PRIuMAX "I64u"
diff --git a/git-compat-util.h b/git-compat-util.h
index 79b5122b4f..15bf3ef810 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -215,6 +215,10 @@ extern char *gitbasename(char *);
#define is_dir_sep(c) ((c) == '/')
#endif
+#ifndef find_last_dir_sep
+#define find_last_dir_sep(path) strrchr(path, '/')
+#endif
+
#if __HP_cc >= 61000
#define NORETURN __attribute__((noreturn))
#define NORETURN_PTR