summaryrefslogtreecommitdiff
path: root/remote-curl.c
diff options
context:
space:
mode:
Diffstat (limited to 'remote-curl.c')
-rw-r--r--remote-curl.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/remote-curl.c b/remote-curl.c
index 0dabef2..b875875 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -43,6 +43,7 @@ struct options {
/* see documentation of corresponding flag in fetch-pack.h */
from_promisor : 1,
+ refetch : 1,
atomic : 1,
object_format : 1,
force_if_includes : 1;
@@ -198,6 +199,9 @@ static int set_option(const char *name, const char *value)
} else if (!strcmp(name, "from-promisor")) {
options.from_promisor = 1;
return 0;
+ } else if (!strcmp(name, "refetch")) {
+ options.refetch = 1;
+ return 0;
} else if (!strcmp(name, "filter")) {
options.filter = xstrdup(value);
return 0;
@@ -576,6 +580,7 @@ struct rpc_state {
char *service_url;
char *hdr_content_type;
char *hdr_accept;
+ char *hdr_accept_language;
char *protocol_header;
char *buf;
size_t alloc;
@@ -603,6 +608,8 @@ struct rpc_state {
unsigned flush_read_but_not_sent : 1;
};
+#define RPC_STATE_INIT { 0 }
+
/*
* Appends the result of reading from rpc->out to the string represented by
* rpc->buf and rpc->len if there is enough space. Returns 1 if there was
@@ -928,6 +935,10 @@ static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_rece
headers = curl_slist_append(headers, needs_100_continue ?
"Expect: 100-continue" : "Expect:");
+ /* Add Accept-Language header */
+ if (rpc->hdr_accept_language)
+ headers = curl_slist_append(headers, rpc->hdr_accept_language);
+
/* Add the extra Git-Protocol header */
if (rpc->protocol_header)
headers = curl_slist_append(headers, rpc->protocol_header);
@@ -1076,6 +1087,8 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads,
strbuf_addf(&buf, "%s%s", url.buf, svc);
rpc->service_url = strbuf_detach(&buf, NULL);
+ rpc->hdr_accept_language = xstrdup_or_null(http_get_accept_language_header());
+
strbuf_addf(&buf, "Content-Type: application/x-%s-request", svc);
rpc->hdr_content_type = strbuf_detach(&buf, NULL);
@@ -1114,6 +1127,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads,
free(rpc->service_url);
free(rpc->hdr_content_type);
free(rpc->hdr_accept);
+ free(rpc->hdr_accept_language);
free(rpc->protocol_header);
free(rpc->buf);
strbuf_release(&buf);
@@ -1149,7 +1163,7 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch)
static int fetch_git(struct discovery *heads,
int nr_heads, struct ref **to_fetch)
{
- struct rpc_state rpc;
+ struct rpc_state rpc = RPC_STATE_INIT;
struct strbuf preamble = STRBUF_INIT;
int i, err;
struct strvec args = STRVEC_INIT;
@@ -1182,6 +1196,8 @@ static int fetch_git(struct discovery *heads,
strvec_push(&args, "--deepen-relative");
if (options.from_promisor)
strvec_push(&args, "--from-promisor");
+ if (options.refetch)
+ strvec_push(&args, "--refetch");
if (options.filter)
strvec_pushf(&args, "--filter=%s", options.filter);
strvec_push(&args, url.buf);
@@ -1293,7 +1309,7 @@ static int push_dav(int nr_spec, const char **specs)
static int push_git(struct discovery *heads, int nr_spec, const char **specs)
{
- struct rpc_state rpc;
+ struct rpc_state rpc = RPC_STATE_INIT;
int i, err;
struct strvec args;
struct string_list_item *cas_option;
@@ -1392,8 +1408,9 @@ free_specs:
static int stateless_connect(const char *service_name)
{
struct discovery *discover;
- struct rpc_state rpc;
+ struct rpc_state rpc = RPC_STATE_INIT;
struct strbuf buf = STRBUF_INIT;
+ const char *accept_language;
/*
* Run the info/refs request and see if the server supports protocol
@@ -1412,6 +1429,9 @@ static int stateless_connect(const char *service_name)
printf("\n");
fflush(stdout);
}
+ accept_language = http_get_accept_language_header();
+ if (accept_language)
+ rpc.hdr_accept_language = xstrfmt("%s", accept_language);
rpc.service_name = service_name;
rpc.service_url = xstrfmt("%s%s", url.buf, rpc.service_name);
@@ -1461,6 +1481,7 @@ static int stateless_connect(const char *service_name)
free(rpc.service_url);
free(rpc.hdr_content_type);
free(rpc.hdr_accept);
+ free(rpc.hdr_accept_language);
free(rpc.protocol_header);
free(rpc.buf);
strbuf_release(&buf);
@@ -1472,11 +1493,12 @@ int cmd_main(int argc, const char **argv)
{
struct strbuf buf = STRBUF_INIT;
int nongit;
+ int ret = 1;
setup_git_directory_gently(&nongit);
if (argc < 2) {
error(_("remote-curl: usage: git remote-curl <remote> [<url>]"));
- return 1;
+ goto cleanup;
}
options.verbosity = 1;
@@ -1508,7 +1530,7 @@ int cmd_main(int argc, const char **argv)
if (strbuf_getline_lf(&buf, stdin) == EOF) {
if (ferror(stdin))
error(_("remote-curl: error reading command stream from git"));
- return 1;
+ goto cleanup;
}
if (buf.len == 0)
break;
@@ -1556,12 +1578,15 @@ int cmd_main(int argc, const char **argv)
break;
} else {
error(_("remote-curl: unknown command '%s' from git"), buf.buf);
- return 1;
+ goto cleanup;
}
strbuf_reset(&buf);
} while (1);
http_cleanup();
+ ret = 0;
+cleanup:
+ strbuf_release(&buf);
- return 0;
+ return ret;
}