git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>,
	Tay Ray Chuan <rctay89@gmail.com>,
	Pang Yan Han <pangyanhan@gmail.com>,
	git@vger.kernel.org, "Shawn O. Pearce" <spearce@spearce.org>,
	Sitaram Chamarty <sitaramc@gmail.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH/RFC 1/2] is_url: Remove redundant assignment
Date: Mon, 26 Sep 2011 17:32:16 -0400	[thread overview]
Message-ID: <20110926213216.GA5415@sigill.intra.peff.net> (raw)
In-Reply-To: <7vsjnj455l.fsf@alter.siamese.dyndns.org>

[+cc Ilari, who wrote the code originally]

On Mon, Sep 26, 2011 at 09:52:54AM -0700, Junio C Hamano wrote:

> Tay Ray Chuan <rctay89@gmail.com> writes:
> 
> > On Sun, Sep 25, 2011 at 1:06 PM, Pang Yan Han <pangyanhan@gmail.com> wrote:
> >> Signed-off-by: Pang Yan Han <pangyanhan@gmail.com>
> >> ---
> >>  url.c |    1 -
> >>  1 files changed, 0 insertions(+), 1 deletions(-)
> >>
> >> diff --git a/url.c b/url.c
> >> index 3e06fd3..d2e17e6 100644
> >> --- a/url.c
> >> +++ b/url.c
> >> @@ -22,7 +22,6 @@ int is_url(const char *url)
> >>
> >>        if (!url)
> >>                return 0;
> >> -       url2 = url;
> >>        first_slash = strchr(url, '/');
> >>
> >>        /* Input with no slash at all or slash first can't be URL. */
> >
> > Looks correct. Perhaps you could mention in the patch message that
> >
> >   There are no operations on url2 until another assignment to it later
> > at line 41.
> 
> The looks correct, so I'll queue it, but it looks like that the function
> is implemented in an overly complicated way.
> 
> Why aren't we checking from left to right in a single pass, perhaps like
> this?
> 
> 	/* Make sure it is of form "scheme://something" */
> 	int is_url(const char *url)
> 	{
> 		/* Is "scheme" part reasonable? */
> 		if (!url || !is_urlschemechar(1, *url++))
> 	        	return 0;
> 		while (*url && *url != ':') {
> 			if (!is_urlschemechar(0, *url++))
> 				return 0;
> 		}
> 		/* We've seen "scheme"; we want colon-slash-slash */
> 		return (url[0] == ':' && url[1] == '/' && url[2] == '/');
> 	}

That looks right to me, and is way more readable.

-Peff

  reply	other threads:[~2011-09-26 21:32 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-25  5:06 [PATCH/RFC 0/2] Teach receive-pack not to run update hook for corrupt/non existent ref Pang Yan Han
2011-09-25  5:06 ` [PATCH/RFC 1/2] is_url: Remove redundant assignment Pang Yan Han
2011-09-25  9:26   ` Tay Ray Chuan
2011-09-26 16:52     ` Junio C Hamano
2011-09-26 21:32       ` Jeff King [this message]
2011-09-25  5:06 ` [PATCH/RFC 2/2] receive-pack: Don't run update hook for corrupt or nonexistent ref Pang Yan Han
2011-09-25 17:37   ` [PATCH/RFCv2 2/2] run post-receive and post-update hooks with empty stdin/no args for invalid ref deletion Pang Yan Han
2011-09-25  7:58 ` [PATCH/RFC 0/2] Teach receive-pack not to run update hook for corrupt/non existent ref Sitaram Chamarty
2011-09-25  9:48   ` Pang Yan Han
2011-09-25 12:05     ` Sitaram Chamarty
2011-09-26 23:23       ` Junio C Hamano
2011-09-26 23:44         ` Sitaram Chamarty
2011-09-26 23:49           ` Junio C Hamano
2011-09-27  0:04             ` Junio C Hamano
2011-09-27  9:02               ` Pang Yan Han
2011-09-27 16:56                 ` Junio C Hamano
2011-09-27 22:55                   ` Pang Yan Han
2011-09-27  0:05             ` Sitaram Chamarty

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=20110926213216.GA5415@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ilari.liusvaara@elisanet.fi \
    --cc=pangyanhan@gmail.com \
    --cc=rctay89@gmail.com \
    --cc=sitaramc@gmail.com \
    --cc=spearce@spearce.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.
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 NNTP newsgroup(s).