From: Johannes Sixt <j6t@kdbg.org>
To: Junio C Hamano <gitster@pobox.com>, Stefan Beller <sbeller@google.com>
Cc: git@vger.kernel.org, peff@peff.net, jens.lehmann@web.de
Subject: Re: [PATCH] submodule: Port resolve_relative_url from shell to C
Date: Thu, 14 Jan 2016 21:57:44 +0100 [thread overview]
Message-ID: <56980BC8.90506@kdbg.org> (raw)
In-Reply-To: <xmqq4mehm92b.fsf@gitster.mtv.corp.google.com>
Am 13.01.2016 um 23:03 schrieb Junio C Hamano:
> Stefan Beller <sbeller@google.com> writes:
>> + while (url) {
>> + if (starts_with_dot_dot_slash(url)) {
>> + char *rfind;
>> + url += 3;
>> +
>> + rfind = last_dir_separator(remoteurl);
>> + if (rfind)
>> + *rfind = '\0';
>> + else {
>> + rfind = strrchr(remoteurl, ':');
>> + if (rfind) {
>> + *rfind = '\0';
>> + colonsep = 1;
>> + } else {
>> + if (is_relative || !strcmp(".", remoteurl))
>> + die(_("cannot strip one component off url '%s'"), remoteurl);
>> + else
>> + remoteurl = xstrdup(".");
>> + }
>> + }
>
> It is somewhat hard to see how this avoids stripping one (or both)
> slashes just after "http:" in remoteurl="http://site/path/", leaving
> just "http:/" (or "http:").
>
> This codepath has overly deep nesting levels. Is this the simplest
> we can do?
The code as written is quite easy to follow when compared to the
original shell code. I think that is a reasonable goal, and improvements
can into separate patches.
>
> The final else { if .. else } can be made into else if .. else to
> dedent the overlong die() by one level, but I am wondering if the
> deep nesting is just a symptom of logic being unnecessarily complex.
>
>> + } else if (starts_with_dot_slash(url)) {
>> + url += 2;
>> + } else
>> + break;
>> + }
For example, the section that begins here...
>> + strbuf_reset(&sb);
>> + strbuf_addf(&sb, "%s%s%s", remoteurl, colonsep ? ":" : "/", url);
>> +
>> + if (starts_with_dot_slash(sb.buf))
>> + out = xstrdup(sb.buf + 2);
>> + else
>> + out = xstrdup(sb.buf);
>> + strbuf_reset(&sb);
>> +
>> + free(remoteurl);
>> + if (!up_path || !is_relative)
>> + return out;
>> +
>> + strbuf_addf(&sb, "%s%s", up_path, out);
>> + free(out);
>> + return strbuf_detach(&sb, NULL);
... and ends here can easily be rewritten to become a single
strbuf_addf() without the xstrdup()s and without the early exit (at the
cost of some additional ?: conditionals in the arguments).
-- Hannes
next prev parent reply other threads:[~2016-01-14 20:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-13 18:15 [PATCH] submodule: Port resolve_relative_url from shell to C Stefan Beller
2016-01-13 22:03 ` Junio C Hamano
2016-01-13 22:47 ` Stefan Beller
2016-01-14 20:50 ` Jens Lehmann
2016-01-14 23:43 ` Stefan Beller
2016-01-15 17:37 ` Junio C Hamano
2016-01-15 22:58 ` Stefan Beller
2016-01-15 23:03 ` Junio C Hamano
2016-01-14 20:57 ` Johannes Sixt [this message]
2016-01-14 22:49 ` Stefan Beller
2016-01-13 22:03 ` Eric Sunshine
2016-01-13 23:37 ` Stefan Beller
-- strict thread matches above, loose matches on Subject: below --
2015-12-10 1:07 Stefan Beller
2015-12-10 6:48 ` Johannes Sixt
2015-12-16 22:36 ` Stefan Beller
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56980BC8.90506@kdbg.org \
--to=j6t@kdbg.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jens.lehmann@web.de \
--cc=peff@peff.net \
--cc=sbeller@google.com \
/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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.