summaryrefslogtreecommitdiff
path: root/remote-curl.c
diff options
context:
space:
mode:
Diffstat (limited to 'remote-curl.c')
-rw-r--r--remote-curl.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/remote-curl.c b/remote-curl.c
index 52c2d96..0fcf2ce 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -194,19 +194,19 @@ static void free_discovery(struct discovery *d)
}
}
-static int show_http_message(struct strbuf *type, struct strbuf *msg)
+static int show_http_message(struct strbuf *type, struct strbuf *charset,
+ struct strbuf *msg)
{
const char *p, *eol;
/*
* We only show text/plain parts, as other types are likely
* to be ugly to look at on the user's terminal.
- *
- * TODO should handle "; charset=XXX", and re-encode into
- * logoutputencoding
*/
- if (strcasecmp(type->buf, "text/plain"))
+ if (strcmp(type->buf, "text/plain"))
return -1;
+ if (charset->len)
+ strbuf_reencode(msg, charset->buf, get_log_output_encoding());
strbuf_trim(msg);
if (!msg->len)
@@ -225,6 +225,7 @@ static struct discovery* discover_refs(const char *service, int for_push)
{
struct strbuf exp = STRBUF_INIT;
struct strbuf type = STRBUF_INIT;
+ struct strbuf charset = STRBUF_INIT;
struct strbuf buffer = STRBUF_INIT;
struct strbuf refs_url = STRBUF_INIT;
struct strbuf effective_url = STRBUF_INIT;
@@ -249,6 +250,7 @@ static struct discovery* discover_refs(const char *service, int for_push)
memset(&options, 0, sizeof(options));
options.content_type = &type;
+ options.charset = &charset;
options.effective_url = &effective_url;
options.base_url = &url;
options.no_cache = 1;
@@ -259,13 +261,13 @@ static struct discovery* discover_refs(const char *service, int for_push)
case HTTP_OK:
break;
case HTTP_MISSING_TARGET:
- show_http_message(&type, &buffer);
+ show_http_message(&type, &charset, &buffer);
die("repository '%s' not found", url.buf);
case HTTP_NOAUTH:
- show_http_message(&type, &buffer);
+ show_http_message(&type, &charset, &buffer);
die("Authentication failed for '%s'", url.buf);
default:
- show_http_message(&type, &buffer);
+ show_http_message(&type, &charset, &buffer);
die("unable to access '%s': %s", url.buf, curl_errorstr);
}
@@ -310,6 +312,7 @@ static struct discovery* discover_refs(const char *service, int for_push)
strbuf_release(&refs_url);
strbuf_release(&exp);
strbuf_release(&type);
+ strbuf_release(&charset);
strbuf_release(&effective_url);
strbuf_release(&buffer);
last_discovery = last;
@@ -396,7 +399,7 @@ static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp)
rpc->pos = 0;
return CURLIOE_OK;
}
- fprintf(stderr, "Unable to rewind rpc post data - try increasing http.postBuffer\n");
+ error("unable to rewind rpc post data - try increasing http.postBuffer");
return CURLIOE_FAILRESTART;
default:
@@ -706,7 +709,7 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch)
free(targets[i]);
free(targets);
- return ret ? error("Fetch failed.") : 0;
+ return ret ? error("fetch failed.") : 0;
}
static int fetch_git(struct discovery *heads,
@@ -788,9 +791,9 @@ static void parse_fetch(struct strbuf *buf)
int alloc_heads = 0, nr_heads = 0;
do {
- if (starts_with(buf->buf, "fetch ")) {
- char *p = buf->buf + strlen("fetch ");
- char *name;
+ const char *p;
+ if (skip_prefix(buf->buf, "fetch ", &p)) {
+ const char *name;
struct ref *ref;
unsigned char old_sha1[20];
@@ -946,7 +949,7 @@ int main(int argc, const char **argv)
git_extract_argv0_path(argv[0]);
setup_git_directory_gently(&nongit);
if (argc < 2) {
- fprintf(stderr, "Remote needed\n");
+ error("remote-curl: usage: git remote-curl <remote> [<url>]");
return 1;
}
@@ -965,18 +968,18 @@ int main(int argc, const char **argv)
http_init(remote, url.buf, 0);
do {
+ const char *arg;
+
if (strbuf_getline(&buf, stdin, '\n') == EOF) {
if (ferror(stdin))
- fprintf(stderr, "Error reading command stream\n");
- else
- fprintf(stderr, "Unexpected end of command stream\n");
+ error("remote-curl: error reading command stream from git");
return 1;
}
if (buf.len == 0)
break;
if (starts_with(buf.buf, "fetch ")) {
if (nongit)
- die("Fetch attempted without a local repo");
+ die("remote-curl: fetch attempted without a local repo");
parse_fetch(&buf);
} else if (!strcmp(buf.buf, "list") || starts_with(buf.buf, "list ")) {
@@ -986,9 +989,8 @@ int main(int argc, const char **argv)
} else if (starts_with(buf.buf, "push ")) {
parse_push(&buf);
- } else if (starts_with(buf.buf, "option ")) {
- char *name = buf.buf + strlen("option ");
- char *value = strchr(name, ' ');
+ } else if (skip_prefix(buf.buf, "option ", &arg)) {
+ char *value = strchr(arg, ' ');
int result;
if (value)
@@ -996,7 +998,7 @@ int main(int argc, const char **argv)
else
value = "true";
- result = set_option(name, value);
+ result = set_option(arg, value);
if (!result)
printf("ok\n");
else if (result < 0)
@@ -1013,7 +1015,7 @@ int main(int argc, const char **argv)
printf("\n");
fflush(stdout);
} else {
- fprintf(stderr, "Unknown command '%s'\n", buf.buf);
+ error("remote-curl: unknown command '%s' from git", buf.buf);
return 1;
}
strbuf_reset(&buf);