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>
Jonathan Tan committed
Feb 14, 2019 at 11:06 UTC
5d91669309d23383651c352abd00254982e31902
1 file changed
+4
-9
remote-curl.c
+4
-9
@@ -505,7 +505,6 @@ static void output_refs(struct ref *refs)
505
506
struct rpc_state {
507
const char *service_name;
508
- struct strbuf *stdin_preamble;
508
char *service_url;
509
char *hdr_content_type;
510
char *hdr_accept;
@@ -829,11 +828,10 @@ retry:
828
}
829
830
static int rpc_service(struct rpc_state *rpc, struct discovery *heads,
832
- const char **client_argv)
831
+ const char **client_argv, const struct strbuf *preamble)
832
{
833
const char *svc = rpc->service_name;
834
struct strbuf buf = STRBUF_INIT;
836
- struct strbuf *preamble = rpc->stdin_preamble;
835
struct child_process client = CHILD_PROCESS_INIT;
836
int err = 0;
837
@@ -843,8 +841,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads,
841
client.argv = client_argv;
842
if (start_command(&client))
843
exit(1);
846
- if (preamble)
847
- write_or_die(client.in, preamble->buf, preamble->len);
844
+ write_or_die(client.in, preamble->buf, preamble->len);
845
if (heads)
846
write_or_die(client.in, heads->buf, heads->len);
847
@@ -978,10 +975,9 @@ static int fetch_git(struct discovery *heads,
975
976
memset(&rpc, 0, sizeof(rpc));
977
rpc.service_name = "git-upload-pack",
981
- rpc.stdin_preamble = &preamble;
978
rpc.gzip_request = 1;
979
984
- err = rpc_service(&rpc, heads, args.argv);
980
+ err = rpc_service(&rpc, heads, args.argv, &preamble);
981
if (rpc.result.len)
982
write_or_die(1, rpc.result.buf, rpc.result.len);
983
strbuf_release(&rpc.result);
@@ -1111,9 +1107,8 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
1107
1108
memset(&rpc, 0, sizeof(rpc));
1109
rpc.service_name = "git-receive-pack",
1114
- rpc.stdin_preamble = &preamble;
1110
1116
- err = rpc_service(&rpc, heads, args.argv);
1111
+ err = rpc_service(&rpc, heads, args.argv, &preamble);
1112
if (rpc.result.len)
1113
write_or_die(1, rpc.result.buf, rpc.result.len);
1114
strbuf_release(&rpc.result);