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

Re: [PATCH/RFC 1/2] is_url: Remove redundant assignment

From
Jeff King <peff@peff.net>
Date
Sep 26, 2011, 21:32 UTC
Message-ID
<20110926213216.GA5415@sigill.intra.peff.net>
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:
Show 45 quoted lines
> 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
Previous: Junio C HamanoNext: Pang Yan Han
Message 5 of 18 in “Teach receive-pack not to run update hook for corrupt/non existent ref”
  1. 0/2 Teach receive-pack not to run update hook for corrupt/non existent refPang Yan Han, Sep 25, 2011
  2. 1/2 is_url: Remove redundant assignmentPang Yan Han, Sep 25, 2011
  3. Tay Ray ChuanSep 25, 2011
  4. Junio C HamanoSep 26, 2011
  5. Jeff KingSep 26, 2011
  6. 2/2 receive-pack: Don't run update hook for corrupt or nonexistent refPang Yan Han, Sep 25, 2011
  7. 2/2 run post-receive and post-update hooks with empty stdin/no args for invalid ref deletionPang Yan Han, Sep 25, 2011
  8. Sitaram ChamartySep 25, 2011
  9. Pang Yan HanSep 25, 2011
  10. Sitaram ChamartySep 25, 2011
  11. Junio C HamanoSep 26, 2011
  12. Sitaram ChamartySep 26, 2011
  13. Junio C HamanoSep 26, 2011
  14. Junio C HamanoSep 27, 2011
  15. Pang Yan HanSep 27, 2011
  16. Junio C HamanoSep 27, 2011
  17. Pang Yan HanSep 27, 2011
  18. Sitaram ChamartySep 27, 2011

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.