summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Jonathan Tan <jonathantanmy@google.com>2019-02-14 11:06:36 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2019-02-14 12:47:55 -0800
commit5d91669309d23383651c352abd00254982e31902 (patch)
treea8774d7cfc42b96bba4d130c760267a0366bb923
parentremote-curl: reduce scope of rpc_state.argv (diff)
downloadtgif-5d91669309d23383651c352abd00254982e31902.tar.xz
remote-curl: reduce scope of rpc_state.stdin_preamble
The stdin_preamble field in struct rpc_state is only used in rpc_service(), and not in any functions it directly or indirectly calls. Refactor it to become an argument of rpc_service() instead. An observation of all callers of rpc_service() shows that the preamble is always set, so we no longer need the "if (preamble)" check. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--remote-curl.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/remote-curl.c b/remote-curl.c
index 8b7baf6298..d33d5bbfa8 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -505,7 +505,6 @@ static void output_refs(struct ref *refs)
struct rpc_state {
const char *service_name;
- struct strbuf *stdin_preamble;
char *service_url;
char *hdr_content_type;
char *hdr_accept;
@@ -829,11 +828,10 @@ retry:
}
static int rpc_service(struct rpc_state *rpc, struct discovery *heads,
- const char **client_argv)
+ const char **client_argv, const struct strbuf *preamble)
{
const char *svc = rpc->service_name;
struct strbuf buf = STRBUF_INIT;
- struct strbuf *preamble = rpc->stdin_preamble;
struct child_process client = CHILD_PROCESS_INIT;
int err = 0;
@@ -843,8 +841,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads,
client.argv = client_argv;
if (start_command(&client))
exit(1);
- if (preamble)
- write_or_die(client.in, preamble->buf, preamble->len);
+ write_or_die(client.in, preamble->buf, preamble->len);
if (heads)
write_or_die(client.in, heads->buf, heads->len);
@@ -978,10 +975,9 @@ static int fetch_git(struct discovery *heads,
memset(&rpc, 0, sizeof(rpc));
rpc.service_name = "git-upload-pack",
- rpc.stdin_preamble = &preamble;
rpc.gzip_request = 1;
- err = rpc_service(&rpc, heads, args.argv);
+ err = rpc_service(&rpc, heads, args.argv, &preamble);
if (rpc.result.len)
write_or_die(1, rpc.result.buf, rpc.result.len);
strbuf_release(&rpc.result);
@@ -1111,9 +1107,8 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
memset(&rpc, 0, sizeof(rpc));
rpc.service_name = "git-receive-pack",
- rpc.stdin_preamble = &preamble;
- err = rpc_service(&rpc, heads, args.argv);
+ err = rpc_service(&rpc, heads, args.argv, &preamble);
if (rpc.result.len)
write_or_die(1, rpc.result.buf, rpc.result.len);
strbuf_release(&rpc.result);