From 137e83f7f2595e373be118b724c2fd18db701c98 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 2 Dec 2017 08:51:15 +0100 Subject: [PATCH] Fix file:// handling for git access. Currently, in is_remote_git_repository(), git URLs of the form "file://..." are recognized as local and the "file://" prefix is removed. The shortened URL is then processed as if it was a remote URL, which of course has to fail. So far so good - this is not a remote repository after all. But the removal of the prefix is not propagated to the calling is_git_repository() function and handling as a local git repository therefore fails likewise. To fix this issue, move removal of the "file://" prefix one level up to the is_git_repository() function. Signed-off-by: Berthold Stoeger --- core/git-access.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/core/git-access.c b/core/git-access.c index 83a8c6054..dc48546a6 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -832,15 +832,10 @@ static struct git_repository *is_remote_git_repository(char *remote, const char if (*p++ != '/' || *p++ != '/') return NULL; - /* Special-case "file://", since it's already local */ - if (!strncmp(remote, "file://", 7)) - remote += 7; - /* - * Ok, we found "[a-z]*://", we've simplified the - * local repo case (because libgit2 is insanely slow - * for that), and we think we have a real "remote - * git" format. + * Ok, we found "[a-z]*://" and we think we have a real + * "remote git" format. The "file://" case was handled + * in the calling function. * * We now create the SHA1 hash of the whole thing, * including the branch name. That will be our unique @@ -905,6 +900,15 @@ struct git_repository *is_git_repository(const char *filename, const char **bran if (!flen || filename[--flen] != ']') return NULL; + /* + * Special-case "file://", and treat it as a local + * repository since libgit2 is insanely slow for that. + */ + if (!strncmp(filename, "file://", 7)) { + filename += 7; + flen -= 7; + } + /* Find the matching '[' */ blen = 0; while (flen && filename[--flen] != '[')