summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8813520)
raw | patch | inline | side by side (parent: 8813520)
author | Theo Niessink <theo@taletn.com> | |
Fri, 27 May 2011 16:00:39 +0000 (18:00 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 27 May 2011 17:59:16 +0000 (10:59 -0700) |
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>
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>
abspath.c | patch | blob | history | |
compat/mingw.h | patch | blob | history | |
git-compat-util.h | patch | blob | history |
diff --git a/abspath.c b/abspath.c
index ff140689ed2453809e7c3794c9989918e90df392..54899008f828963cdefa7523d82a44588841e82c 100644 (file)
--- a/abspath.c
+++ b/abspath.c
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);
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 14211c6214ea4654e0bb9dd25b29d7b28ac6141d..bea909d76f2c7ab94fd51091258eb91404013df8 100644 (file)
--- 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 79b5122b4f75697413b23b45646813bef8705ba9..15bf3ef81010a90498e4773f54e39a9286a9f0c5 100644 (file)
--- a/git-compat-util.h
+++ b/git-compat-util.h
#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