From: Tay Ray Chuan <rctay89@gmail•com>
To: git@vger•kernel.org, Johannes Schindelin <johannes.schindelin@gmx•de>
Subject: [PATCH] http: use strbuf API in quote_ref_url
Date: Sat, 07 Mar 2009 23:40:04 +0800 [thread overview]
Message-ID: <49B29554.30805@gmail.com> (raw)
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>
---
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, "/");
- baselen = strlen(base);
- len = baselen + 2; /* '/' after base and terminating NUL */
- for (cp = ref; (ch = *cp) != 0; cp++, len++)
- if (needs_quote(ch))
- len += 2; /* extra two hex plus replacement % */
- qref = xmalloc(len);
- memcpy(qref, base, baselen);
- dp = qref + baselen;
- *(dp++) = '/';
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);
}
- *dp = 0;
- return qref;
+ return strbuf_detach(&buf, NULL);
}
int http_fetch_ref(const char *base, struct ref *ref)
--
1.6.2.rc1
next reply other threads:[~2009-03-07 15:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-07 15:40 Tay Ray Chuan [this message]
2009-03-07 15:57 ` [PATCH] http: use strbuf API in quote_ref_url Johannes Schindelin
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=49B29554.30805@gmail.com \
--to=rctay89@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=johannes.schindelin@gmx$(echo .)de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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