git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 5/6] clone: fix hostname parsing when guessing dir

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 29, 2015, 17:42 UTC
Message-ID
<xmqq7fpiamiq.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1438185076-28870-6-git-send-email-ps@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 6 quoted lines
> We fail to guess a sensible directory name for a newly cloned
> repository when the path component of the URL is empty. E.g.
> cloning a repository 'ssh://user:password@example.com/' we create
> a directory 'password@example.com' for the clone.
>
> Fix this by ...

It is clear that you do not want to have that password in the resulting directory name from the problem description, but you started saying "Fix this" without saying what the desired outcome is. "We want to use only the hostname, e.g. 'example.com', in such a case instead." or something, perhaps, at the end of the first paragraph? "Fix this by doing such and such" becomes understandable only after we know what end result you want to achieve by "doing such and such".

> ... using parse_connect_url to split host and path
> components and explicitly checking whether we need to fall back
> to the hostname for guessing a directory name.
I cannot help wonder why this much change (including patches 3 and
4) is needed.  Isn't it just the matter of making this part of the
existing code be aware of '@' in addition to ':'?
Show 8 quoted lines
> -	/*
> -	 * Find last component, but be prepared that repo could have
> -	 * the form  "remote.example.com:foo.git", i.e. no slash
> -	 * in the directory part.
> -	 */
> -	start = end;
> -	while (repo < start && !is_dir_sep(start[-1]) && start[-1] != ':')
> -		start--;

Regardless of the issue you are trying to address, we may want to limit that "be prepared for and careful with ':'" logic in the existing code to the case where the "last component" does not have any other component before it. That is:

	http://example.com/foo:bar.git/
would be stripped to
	http://example.com/foo:bar

and then we scan backwards for ':' or '/' and declare that "bar" is the name of the repository, but we would probably want "foo:bar" instead (or we may not, as some filesystems do not want to have a colon in its path components).

 builtin/clone.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index a72ff7e..3d6328a 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -165,10 +165,12 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
 	/*
 	 * Find last component, but be prepared that repo could have
 	 * the form  "remote.example.com:foo.git", i.e. no slash
-	 * in the directory part.
+	 * in the directory part, or "http://user@example.com/" with
+	 * the whole site serving a single repository.
 	 */
 	start = end;
-	while (repo < start && !is_dir_sep(start[-1]) && start[-1] != ':')
+	while (repo < start &&
+	       !(is_dir_sep(start[-1]) || start[-1] == ':' || start[-1] == '@'))
 		start--;
 
 	/*
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 13 of 53 in “clone: fix repo name when cloning a server's root”
  1. clone: fix repo name when cloning a server's rootPatrick Steinhardt, Jul 27, 2015
  2. Duy NguyenJul 27, 2015
  3. Patrick SteinhardtJul 27, 2015
  4. Junio C HamanoJul 27, 2015
  5. 0/6 clone: fix repo name when cloning a server's rootPatrick Steinhardt, Jul 29, 2015
  6. 1/6 tests: fix broken && chains in t1509-root-worktreePatrick Steinhardt, Jul 29, 2015
  7. 2/6 tests: fix cleanup after tests in t1509-root-worktreePatrick Steinhardt, Jul 29, 2015
  8. 3/6 connect: expose parse_connect_url()Patrick Steinhardt, Jul 29, 2015
  9. 4/6 connect: move error check to caller of parse_connect_urlPatrick Steinhardt, Jul 29, 2015
  10. Eric SunshineJul 29, 2015
  11. Patrick SteinhardtJul 30, 2015
  12. 5/6 clone: fix hostname parsing when guessing dirPatrick Steinhardt, Jul 29, 2015
  13. Junio C HamanoJul 29, 2015
  14. Patrick SteinhardtJul 30, 2015
  15. Junio C HamanoJul 30, 2015
  16. Junio C HamanoJul 30, 2015
  17. Patrick SteinhardtAug 3, 2015
  18. Jeff KingAug 3, 2015
  19. Junio C HamanoAug 3, 2015
  20. 6/6 clone: add tests for cloning with empty pathPatrick Steinhardt, Jul 29, 2015
  21. Eric SunshineJul 30, 2015
  22. Junio C HamanoJul 31, 2015
  23. Patrick SteinhardtJul 31, 2015
  24. 0/6 fix repo name when cloning a server's rootPatrick Steinhardt, Aug 4, 2015
  25. 1/6 tests: fix broken && chains in t1509-root-worktreePatrick Steinhardt, Aug 4, 2015
  26. 2/6 tests: fix cleanup after tests in t1509-root-worktreePatrick Steinhardt, Aug 4, 2015
  27. 3/6 clone: do not include authentication data in guessed dirPatrick Steinhardt, Aug 4, 2015
  28. 4/6 clone: do not use port number as dir namePatrick Steinhardt, Aug 4, 2015
  29. 5/6 clone: abort if no dir name could be guessedPatrick Steinhardt, Aug 4, 2015
  30. 6/6 clone: add tests for cloning with empty pathPatrick Steinhardt, Aug 4, 2015
  31. Eric SunshineAug 4, 2015
  32. Junio C HamanoAug 5, 2015
  33. Jeff KingAug 5, 2015
  34. Torsten BögershausenAug 6, 2015
  35. Junio C HamanoAug 6, 2015
  36. 0/3 fix repo name when cloning a server's rootPatrick Steinhardt, Aug 5, 2015
  37. 1/3 clone: do not include authentication data in guessed dirPatrick Steinhardt, Aug 5, 2015
  38. Junio C HamanoAug 5, 2015
  39. Junio C HamanoAug 5, 2015
  40. Junio C HamanoAug 5, 2015
  41. Patrick SteinhardtAug 6, 2015
  42. Junio C HamanoAug 7, 2015
  43. Patrick SteinhardtAug 8, 2015
  44. 2/3 clone: do not use port number as dir namePatrick Steinhardt, Aug 5, 2015
  45. 3/3 clone: abort if no dir name could be guessedPatrick Steinhardt, Aug 5, 2015
  46. Junio C HamanoAug 5, 2015
  47. 0/5 Improve guessing of repository namesPatrick Steinhardt, Aug 10, 2015
  48. 1/5 clone: add tests for output directoryPatrick Steinhardt, Aug 10, 2015
  49. 2/5 clone: use computed length in guess_dir_namePatrick Steinhardt, Aug 10, 2015
  50. 3/5 clone: do not include authentication data in guessed dirPatrick Steinhardt, Aug 10, 2015
  51. 4/5 clone: do not use port number as dir namePatrick Steinhardt, Aug 10, 2015
  52. 5/5 clone: abort if no dir name could be guessedPatrick Steinhardt, Aug 10, 2015
  53. Junio C HamanoAug 10, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.