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

Re: [PATCH] http: use strbuf API in quote_ref_url

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Mar 7, 2009, 15:57 UTC
Message-ID
<alpine.DEB.1.00.0903071654480.10279@pacific.mpi-cbg.de>
In-Reply-To
<49B29554.30805@gmail.com>
Hi,
On Sat, 7 Mar 2009, Tay Ray Chuan wrote:
Show 7 quoted lines
> In addition, ''quote_ref_url'' inserts a slash between the base URL and
> remote ref path only if needed. Previously, this insertion wasn't
> contingent on the lack of a separating slash.
> 
> Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
> Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
I would prefer to give my ACK explicitely... :-)
Show 20 quoted lines
>  http.c |   29 ++++++++++-------------------
>  1 files changed, 10 insertions(+), 19 deletions(-)
> 
> diff --git a/http.c b/http.c
> index cdedeb6..9de4130 100644
> --- a/http.c
> +++ b/http.c
> @@ -577,31 +577,22 @@ static inline int hex(int v)
> 
>  static char *quote_ref_url(const char *base, const char *ref)
>  {
> +	struct strbuf buf = STRBUF_INIT;
>  	const char *cp;
> -	char *dp, *qref;
> -	int len, baselen, ch;
> +	int ch;
> +
> +	strbuf_addstr(&buf, base);
> +	if (strcmp(base+strlen(base)-1, "/") && strcmp(ref, "/"))
> +		strbuf_addstr(&buf, "/");
I would not have scratched my head that much if it read like this:
	if (buf.len && buf.buf[buf.len - 1] != '/' && *ref != '/')
		strbuf_addch(&buf, '/');
Show 12 quoted lines
>  	for (cp = ref; (ch = *cp) != 0; cp++) {
> -		if (needs_quote(ch)) {
> -			*dp++ = '%';
> -			*dp++ = hex((ch >> 4) & 0xF);
> -			*dp++ = hex(ch & 0xF);
> -		}
> +		if (needs_quote(ch))
> +			strbuf_addf(&buf, "%%%02x", ch);
>  		else
> -			*dp++ = ch;
> +			strbuf_addch(&buf, *cp);
>  	}
Seems as if you could remove even the curly brackets here.
Other than that, it indeed looks like an ACK from me...

Ciao, Dscho

Previous: Tay Ray Chuan
Message 2 of 2 in “http: use strbuf API in quote_ref_url”
  1. http: use strbuf API in quote_ref_urlTay Ray Chuan, Mar 7, 2009
  2. Johannes SchindelinMar 7, 2009

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.