http.c: don't rewrite the user:passwd string multiple times
[gitweb.git] / http.c
diff --git a/http.c b/http.c
index d9d1aad3be468394e39966c0b45e7e101b387b0c..c02246a78b954569e9c6d5757f7ffe7464e97424 100644 (file)
--- a/http.c
+++ b/http.c
@@ -222,9 +222,15 @@ static void init_curl_http_auth(CURL *result)
 #else
        {
                static struct strbuf up = STRBUF_INIT;
-               strbuf_reset(&up);
-               strbuf_addf(&up, "%s:%s",
-                           http_auth.username, http_auth.password);
+               /*
+                * Note that we assume we only ever have a single set of
+                * credentials in a given program run, so we do not have
+                * to worry about updating this buffer, only setting its
+                * initial value.
+                */
+               if (!up.len)
+                       strbuf_addf(&up, "%s:%s",
+                               http_auth.username, http_auth.password);
                curl_easy_setopt(result, CURLOPT_USERPWD, up.buf);
        }
 #endif