Signed-off-by: Nguyễn Thái Ngọc Duy <pclo...@gmail.com>
---
 setup.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/setup.c b/setup.c
index e9f0ef6..01fe89a 100644
--- a/setup.c
+++ b/setup.c
@@ -182,28 +182,38 @@ void verify_non_filename(const char *prefix, const char 
*arg)
  *    a proper "ref:", or a regular file HEAD that has a properly
  *    formatted sha1 object name.
  */
-int is_git_directory(const char *suspect)
+static int is_git_directory_super(const char *suspect, const char *super)
 {
        char path[PATH_MAX];
        size_t len = strlen(suspect);
+       size_t super_len;
+
+       if (!super) {
+               super = suspect;
+               super_len = len;
+       } else
+               super_len = strlen(super);
 
-       if (PATH_MAX <= len + strlen("/objects"))
+       if (PATH_MAX <= super_len + strlen("/objects") ||
+           PATH_MAX <= len + strlen("/HEAD"))
                die("Too long path: %.*s", 60, suspect);
-       strcpy(path, suspect);
+       strcpy(path, super);
        if (getenv(DB_ENVIRONMENT)) {
                if (access(getenv(DB_ENVIRONMENT), X_OK))
                        return 0;
        }
        else {
-               strcpy(path + len, "/objects");
+               strcpy(path + super_len, "/objects");
                if (access(path, X_OK))
                        return 0;
        }
 
-       strcpy(path + len, "/refs");
+       strcpy(path + super_len, "/refs");
        if (access(path, X_OK))
                return 0;
 
+       if (super != suspect)
+               strcpy(path, suspect);
        strcpy(path + len, "/HEAD");
        if (validate_headref(path))
                return 0;
@@ -211,6 +221,12 @@ int is_git_directory(const char *suspect)
        return 1;
 }
 
+int is_git_directory(const char *suspect)
+{
+       return is_git_directory_super(suspect, NULL);
+}
+
+
 int is_inside_git_dir(void)
 {
        if (inside_git_dir < 0)
@@ -354,7 +370,7 @@ const char *read_gitfile_super(const char *path, char 
**super)
                dir = path_from_gitfile(path, buf + 8, len - 8);
        }
 
-       if (!is_git_directory(dir))
+       if (!is_git_directory_super(dir, super ? *super : NULL))
                die("Not a git repository: %s", dir);
        path = real_path(dir);
 
-- 
1.8.5.1.77.g42c48fa

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to