Skip to content

Commit df8e052

Browse files
attempt with inlined impl
1 parent 3527d87 commit df8e052

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

remote-curl.c

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "transport.h"
2727
#include "url.h"
2828
#include "write-or-die.h"
29+
#include "utf8.h"
2930

3031
static struct remote *remote;
3132
/* always ends with a trailing slash */
@@ -540,10 +541,38 @@ static struct discovery *discover_refs(const char *service, int for_push)
540541
show_http_message_fatal(&type, &charset, &buffer,
541542
_("unable to access '%s' with http.pinnedPubkey configuration: %s"),
542543
transport_anonymize_url(url.buf), curl_errorstr);
543-
case HTTP_RATE_LIMITED:
544-
show_http_message_fatal(&type, &charset, &buffer,
545-
_("rate limited by '%s', please try again later"),
546-
transport_anonymize_url(url.buf));
544+
case HTTP_RATE_LIMITED: {
545+
const char *p, *eol;
546+
struct strbuf msgbuf = STRBUF_INIT;
547+
char *anonymized_url = transport_anonymize_url(url.buf);
548+
549+
/*
550+
* We only show text/plain parts, as other types are likely
551+
* to be ugly to look at on the user's terminal.
552+
*/
553+
if (!strcmp(type.buf, "text/plain")) {
554+
strbuf_addbuf(&msgbuf, &buffer);
555+
if (charset.len)
556+
strbuf_reencode(&msgbuf, charset.buf, get_log_output_encoding());
557+
558+
strbuf_trim(&msgbuf);
559+
if (msgbuf.len) {
560+
p = msgbuf.buf;
561+
do {
562+
eol = strchrnul(p, '\n');
563+
fprintf(stderr, "remote: %.*s\n", (int)(eol - p), p);
564+
p = eol + 1;
565+
} while(*eol);
566+
}
567+
strbuf_release(&msgbuf);
568+
}
569+
570+
strbuf_release(&type);
571+
strbuf_release(&charset);
572+
strbuf_release(&buffer);
573+
574+
die(_("rate limited by '%s', please try again later"), anonymized_url);
575+
}
547576
default:
548577
show_http_message_fatal(&type, &charset, &buffer,
549578
_("unable to access '%s': %s"),

0 commit comments

Comments
 (0)