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

Re: [PATCH] ignore trailing slash when creating leading directories

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 2, 2008, 18:38 UTC
Message-ID
<7vk5dul7f5.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20080902081909.GA2059@localhost>
Clemens Buchacher <drizzd@aon.at> writes:
Show 7 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 a trailing slash is ignored.
>
> Signed-off-by: Clemens Buchacher <drizzd@aon.at>
Thanks.
I have a few comments.
 (1) Addition of strerror(errno) is a good thing, but it is a separate
     topic;
 (2) I always thought that it was a clever feature to allow callers that
     would want to prepare a directory in advance to ask for "xyzzy/" and
     cause the whole path created.  You are breaking it, which may or may
     not be a bad thing per-se, because I do not think any existing caller
     depends on this behaviour;
 (3) If you *are* to break that feature, then I think you should also
     handle a user input that is broken in the same fashion as your clone
     example, namely, "git clone <repo> path//".  It does not make much
     senseto say "path/" as the last parameter to clone is not a user
     error but "path//" is.

If a change in behaviour to strip trailing slashes inside safe_c_l_d() is agreed to be a good thing (I do not mind that myself, but there could be some private patches people are using in their trees that depend on the current behaviour --- we never know), I think it should go through the usual next-master cycle as a feature enhancement / clean-up patch, so that we have better chance to catch breakages this might cause to other people.

As a "bugfix" patch meant to apply to 'maint', I'd prefer a fix to the caller (builtin-clone.c that calls the function), which should be of much less impact. It is fine to include the change to add strerror(errno) in that patch, whose title would be "clone: fix creation of explicitly named target directory".

Show 10 quoted lines
> diff --git a/sha1_file.c b/sha1_file.c
> index 9ee1ed1..3cb9414 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -97,7 +97,7 @@ int safe_create_leading_directories(char *path)
>  
>  	while (pos) {
>  		pos = strchr(pos, '/');
> -		if (!pos)
> +		if (!pos || !*(pos + 1))
(minor nit) I think
		if (!pos || !pos[1])
is shorter and easier on the eye.
Show 5 quoted lines
>  			break;
>  		*pos = 0;
>  		if (!stat(path, &st)) {
> -- 
> 1.6.0
Previous: Clemens BuchacherNext: Clemens Buchacher
Message 2 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.