From: Junio C Hamano <gitster@pobox.com>
To: Clemens Buchacher <drizzd@aon.at>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] clone: fix creation of explicitly named target directory
Date: Wed, 03 Sep 2008 12:24:31 -0700 [thread overview]
Message-ID: <7vprnlav80.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <20080903185554.GA6738@localhost> (Clemens Buchacher's message of "Wed, 3 Sep 2008 20:55:55 +0200")
Clemens Buchacher <drizzd@aon.at> writes:
> '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.
> +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.
> @@ -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.
prev parent reply other threads:[~2008-09-03 19:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-02 8:19 [PATCH] ignore trailing slash when creating leading directories Clemens Buchacher
2008-09-02 18:38 ` Junio C Hamano
2008-09-02 19:13 ` Clemens Buchacher
2008-09-02 20:07 ` [PATCH v2] ignore trailing slashes " Clemens Buchacher
2008-09-02 20:36 ` [PATCH] ignore trailing slash " Junio C Hamano
2008-09-02 21:10 ` Junio C Hamano
2008-09-03 19:02 ` Clemens Buchacher
2008-09-03 18:55 ` [PATCH] clone: fix creation of explicitly named target directory Clemens Buchacher
2008-09-03 19:24 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vprnlav80.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=drizzd@aon.at \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).