git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Stefan Beller <sbeller@google.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>,
	Jens Lehmann <Jens.Lehmann@web.de>,
	Eric Sunshine <sunshine@sunshineco.com>,
	Johannes Sixt <j6t@kdbg.org>
Subject: Re: [PATCHv4 1/2] submodule: port resolve_relative_url from shell to C
Date: Thu, 28 Jan 2016 14:11:06 -0800	[thread overview]
Message-ID: <CAGZ79kYbYEgW+O-wxp0LeT6W5XweV8e0jWzYDRS6vunnOJBKng@mail.gmail.com> (raw)
In-Reply-To: <xmqqzivpl5uo.fsf@gitster.mtv.corp.google.com>

On Thu, Jan 28, 2016 at 2:03 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> +static char *relative_url(const char *remote_url,
>> +                             const char *url,
>> +                             const char *up_path)
>> +{
>> +     int is_relative = 0;
>> +     int colonsep = 0;
>> +     char *out;
>> +     char *remoteurl = xstrdup(remote_url);
>> +     struct strbuf sb = STRBUF_INIT;
>> +     size_t len = strlen(remoteurl);
>> +
>> +     if (is_dir_sep(remoteurl[len]))
>> +             remoteurl[len] = '\0';
>> +
>> +     if (!url_is_local_not_ssh(remoteurl) || is_absolute_path(remoteurl))
>> +             is_relative = 0;
>> +     else {
>> +             is_relative = 1;
>> +             /*
>> +              * Prepend a './' to ensure all relative
>> +              * remoteurls start with './' or '../'
>> +              */
>> +             if (!starts_with_dot_slash(remoteurl) &&
>> +                 !starts_with_dot_dot_slash(remoteurl)) {
>> +                     strbuf_reset(&sb);
>> +                     strbuf_addf(&sb, "./%s", remoteurl);
>> +                     free(remoteurl);
>> +                     remoteurl = strbuf_detach(&sb, NULL);
>> +             }
>> +     }
>> +     /*
>> +      * When the url starts with '../', remove that and the
>> +      * last directory in remoteurl.
>> +      */
>> +     while (url) {
>> +             if (starts_with_dot_dot_slash(url)) {
>> +                     url += 3;
>> +                     colonsep |= chop_last_dir(&remoteurl, is_relative);
>> +             } else if (starts_with_dot_slash(url))
>> +                     url += 2;
>> +             else
>> +                     break;
>> +     }
>> +     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);
>
> This is a rather strange place to put this free(), as you are done
> with it a bit earlier, but it's OK.  I briefly wondered if the code
> becomes easier to follow with fewer free(remoteurl) if this local
> variable is made into a strbuf, but I didn't seriously think it
> through.

Right. As I did not touch that particular free with the resend, I wondered
how it came there, too. And I think I had it at the end of the function and
then realized the return just after the current position would leak it, so
I moved it minimally up. If I'll resend again, I'll move it up to where
it was last used.

>
> Otherwise looking good.
>
> Thanks.

Thanks,
Stefan

  reply	other threads:[~2016-01-28 22:11 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-15 23:37 [PATCH 0/2] Port `git submodule init` from shell to C Stefan Beller
2016-01-15 23:37 ` [PATCH 1/2] submodule: Port resolve_relative_url " Stefan Beller
2016-01-15 23:37 ` [PATCH 2/2] submodule: Port init " Stefan Beller
2016-01-19 23:17 ` [PATCH 0/2] Port `git submodule init` " Junio C Hamano
2016-01-20  2:03   ` [PATCHv2 " Stefan Beller
2016-01-20  2:03     ` [PATCHv2 1/2] submodule: port resolve_relative_url " Stefan Beller
2016-01-22 19:03       ` Johannes Sixt
2016-01-22 20:23         ` Stefan Beller
2016-01-20  2:03     ` [PATCHv2 2/2] submodule: port init " Stefan Beller
2016-01-20  3:24       ` [PATCHv3 " Stefan Beller
2016-01-20 21:01         ` Junio C Hamano
2016-01-20 22:33           ` Stefan Beller
2016-01-20 23:04             ` Junio C Hamano
2016-01-21 23:18         ` [PATCHv4 " Stefan Beller
2016-01-22 22:30           ` Junio C Hamano
2016-01-22 22:32             ` Stefan Beller
2016-01-22 23:32             ` [PATCHv3 0/2] Port `git submodule init` " Stefan Beller
2016-01-25 22:46               ` Junio C Hamano
2016-01-28  2:30                 ` [PATCHv4 " Stefan Beller
2016-01-28  2:30                   ` [PATCHv4 1/2] submodule: port resolve_relative_url " Stefan Beller
2016-01-28 22:03                     ` Junio C Hamano
2016-01-28 22:11                       ` Stefan Beller [this message]
2016-01-28  2:30                   ` [PATCHv4 2/2] submodule: port init " Stefan Beller
2016-02-27  8:30                     ` Duy Nguyen
2016-01-22 23:32             ` [PATCHv3 1/2] submodule: port resolve_relative_url " Stefan Beller
2016-01-22 23:32             ` [PATCHv3 2/2] submodule: port init " 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

  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=CAGZ79kYbYEgW+O-wxp0LeT6W5XweV8e0jWzYDRS6vunnOJBKng@mail.gmail.com \
    --to=sbeller@google.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=sunshine@sunshineco.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.
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).