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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2017-12-02 08:51:15 +01:00 committed by Dirk Hohndel
parent 136110784e
commit 137e83f7f2

View file

@ -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] != '[')