Refactor skipping DOS drive prefixes
[gitweb.git] / path.c
diff --git a/path.c b/path.c
index 69265f42cec4cfb19f6651b0dc845d2ab744711d..747d6da2c87edff4a1d1f2d20a4111d9f3a4e9d8 100644 (file)
--- a/path.c
+++ b/path.c
@@ -147,7 +147,7 @@ void report_linked_checkout_garbage(void)
                strbuf_setlen(&sb, len);
                strbuf_addstr(&sb, path);
                if (file_exists(sb.buf))
-                       report_garbage("unused in linked checkout", sb.buf);
+                       report_garbage(PACKDIR_FILE_GARBAGE, sb.buf);
        }
        strbuf_release(&sb);
 }
@@ -445,18 +445,22 @@ const char *enter_repo(const char *path, int strict)
                }
                if (!suffix[i])
                        return NULL;
-               gitfile = read_gitfile(used_path) ;
+               gitfile = read_gitfile(used_path);
                if (gitfile)
                        strcpy(used_path, gitfile);
                if (chdir(used_path))
                        return NULL;
                path = validated_path;
        }
-       else if (chdir(path))
-               return NULL;
+       else {
+               const char *gitfile = read_gitfile(path);
+               if (gitfile)
+                       path = gitfile;
+               if (chdir(path))
+                       return NULL;
+       }
 
-       if (access("objects", X_OK) == 0 && access("refs", X_OK) == 0 &&
-           validate_headref("HEAD") == 0) {
+       if (is_git_directory(".")) {
                set_git_dir(".");
                check_repository_format();
                return path;
@@ -540,13 +544,10 @@ const char *relative_path(const char *in, const char *prefix,
        else if (!prefix_len)
                return in;
 
-       if (have_same_root(in, prefix)) {
+       if (have_same_root(in, prefix))
                /* bypass dos_drive, for "c:" is identical to "C:" */
-               if (has_dos_drive_prefix(in)) {
-                       i = 2;
-                       j = 2;
-               }
-       } else {
+               i = j = has_dos_drive_prefix(in);
+       else {
                return in;
        }
 
@@ -699,11 +700,10 @@ const char *remove_leading_path(const char *in, const char *prefix)
 int normalize_path_copy_len(char *dst, const char *src, int *prefix_len)
 {
        char *dst0;
+       int i;
 
-       if (has_dos_drive_prefix(src)) {
-               *dst++ = *src++;
+       for (i = has_dos_drive_prefix(src); i > 0; i--)
                *dst++ = *src++;
-       }
        dst0 = dst;
 
        if (is_dir_sep(*src)) {