All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Tan <jonathantanmy@google.com>
To: git@vger.kernel.org
Cc: Jonathan Tan <jonathantanmy@google.com>, peff@peff.net
Subject: [PATCH v2 2/5] remote-curl: reduce scope of rpc_state.stdin_preamble
Date: Thu, 21 Feb 2019 12:24:38 -0800	[thread overview]
Message-ID: <23d2414994e8ca2559940ccd43df0e2b2ceb712b.1550780213.git.jonathantanmy@google.com> (raw)
In-Reply-To: <cover.1550780213.git.jonathantanmy@google.com>

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>
---
 remote-curl.c | 13 ++++---------
 1 file 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 @@ static int post_rpc(struct rpc_state *rpc)
 }
 
 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);
-- 
2.19.0.271.gfe8321ec05.dirty


  parent reply	other threads:[~2019-02-21 20:24 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-14 19:06 [PATCH 0/5] Protocol v2 fix: http and auth Jonathan Tan
2019-02-14 19:06 ` [PATCH 1/5] remote-curl: reduce scope of rpc_state.argv Jonathan Tan
2019-02-14 19:06 ` [PATCH 2/5] remote-curl: reduce scope of rpc_state.stdin_preamble Jonathan Tan
2019-02-14 19:06 ` [PATCH 3/5] remote-curl: reduce scope of rpc_state.result Jonathan Tan
2019-02-14 19:06 ` [PATCH 4/5] remote-curl: refactor reading into rpc_state's buf Jonathan Tan
2019-02-14 19:06 ` [PATCH 5/5] remote-curl: use post_rpc() for protocol v2 also Jonathan Tan
2019-02-14 22:47   ` Junio C Hamano
2019-02-21 13:46   ` Jeff King
2019-02-21 19:26     ` Jonathan Tan
2019-02-21 13:47 ` [PATCH 0/5] Protocol v2 fix: http and auth Jeff King
2019-02-21 20:24 ` [PATCH v2 " Jonathan Tan
2019-02-21 20:24   ` [PATCH v2 1/5] remote-curl: reduce scope of rpc_state.argv Jonathan Tan
2019-02-21 20:24   ` Jonathan Tan [this message]
2019-02-21 20:24   ` [PATCH v2 3/5] remote-curl: reduce scope of rpc_state.result Jonathan Tan
2019-02-21 20:24   ` [PATCH v2 4/5] remote-curl: refactor reading into rpc_state's buf Jonathan Tan
2019-02-21 20:24   ` [PATCH v2 5/5] remote-curl: use post_rpc() for protocol v2 also Jonathan Tan
2019-02-22 13:18     ` Eric Sunshine
2019-02-22 19:15       ` Eric Sunshine
2019-02-25 22:08     ` Jeff King
2019-02-25 23:49       ` [FIXUP] Fixup on tip of jt/http-auth-proto-v2-fix Jonathan Tan
2019-02-26  7:04         ` Jonathan Nieder
2019-02-26 18:18           ` Jonathan Tan
2019-03-04  3:45             ` Junio C Hamano
2019-02-27 12:02         ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=23d2414994e8ca2559940ccd43df0e2b2ceb712b.1550780213.git.jonathantanmy@google.com \
    --to=jonathantanmy@google.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.