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

Re: [PATCH] clone: fix creation of explicitly named target directory

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 3, 2008, 19:24 UTC
Message-ID
<7vprnlav80.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20080903185554.GA6738@localhost>
Clemens Buchacher <drizzd@aon.at> writes:
Show 5 quoted lines
> 'git clone <repo> path/' (note the trailing slash) fails, because the
> entire path is interpreted as leading directories. So when mkdir tries to
> create the actual path, it already exists.
>
> This makes sure trailing slashes are removed.
Thanks.
Show 7 quoted lines
> +static char *strip_dir_sep(char *dir)
> +{
> +	char *end = dir + strlen(dir);
> +
> +	while (dir < end && is_dir_sep(end[-1]))
> +		end--;
> +	*end = '\0';

It does not matter in this particular context, but I'd do "dir < end - 1" to avoid returning the root directory as an empty string, just as a disciplined style; also I'd rename this to strip_trailing_slashes(), make it of type void to make it more clear that it munges the string that is given as the input parameter.

Show 8 quoted lines
> @@ -394,7 +405,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>  		repo = repo_name;
>  
>  	if (argc == 2)
> -		dir = xstrdup(argv[1]);
> +		dir = strip_dir_sep(xstrdup(argv[1]));
>  	else
>  		dir = guess_dir_name(repo_name, is_bundle, option_bare);

Made me wonder if guess_dir_name() can return something with trailing slashes; it turns out that it doesn't, but not very nice. As people's braincycle is more precious, I'd rather say:

	if (argc == 2)
        	dir = xstrdup(argv[1]);
	else
        	dir = guess_dir_name(repo_name, is_bundle, option_bare);
	strip_trailing_slashes(dir);

I'll queue with the above changes to reduce one round of back-and-forth, but if you see any flaws in my above reasoning, please say so.

Previous: Clemens Buchacher
Message 9 of 9 in “ignore trailing slash when creating leading directories”
  1. ignore trailing slash when creating leading directoriesClemens Buchacher, Sep 2, 2008
  2. Junio C HamanoSep 2, 2008
  3. Clemens BuchacherSep 2, 2008
  4. ignore trailing slashes when creating leading directoriesClemens Buchacher, Sep 2, 2008
  5. Junio C HamanoSep 2, 2008
  6. Junio C HamanoSep 2, 2008
  7. Clemens BuchacherSep 3, 2008
  8. clone: fix creation of explicitly named target directoryClemens Buchacher, Sep 3, 2008
  9. Junio C HamanoSep 3, 2008

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.