[PATCH v3 4/6] clone: do not use port number as dir name
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Aug 4, 2015, 11:29 UTC
- Message-ID
- <1438687797-14254-5-git-send-email-ps@pks.im>
- In-Reply-To
- <1438687797-14254-1-git-send-email-ps@pks.im>
If the URI contains a port number and the URI's path component is empty we fail to guess a sensible directory name. E.g. cloning a repository 'ssh://example.com:2222/' we guess a directory name '2222' where we would want the hostname only, e.g. 'example.com'.
Fix this by stripping trailing port numbers.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- builtin/clone.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
diff --git a/builtin/clone.c b/builtin/clone.c index 794a933..a163797 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -181,6 +181,23 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare) } /* + * Strip trailing port number if we've got only a + * hostname (that is, there is no dir separator but a + * colon). This check is required such that we do not + * strip URI's like '/foo/bar:2222.git', which should + * result in a dir '2222' being guessed due to backwards + * compatibility. + */ + if (memchr(start, '/', end - start) == NULL + && memchr(start, ':', end - start) != NULL) { + ptr = end; + while (start < ptr && isdigit(ptr[-1]) && ptr[-1] != ':') + ptr--; + if (start < ptr && ptr[-1] == ':') + end = ptr - 1; + } + + /* * Find last component. To remain backwards compatible we * also regard colons as path separators, such that * cloning a repository 'foo:bar.git' would result in a
-- 2.5.0