git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/5] remote-curl: reduce scope of rpc_state.result

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Feb 14, 2019, 19:06 UTC
Message-ID
<db10ed20ff11eda56b14ca0667a0b42ab651b0b5.1550170980.git.jonathantanmy@google.com>
In-Reply-To
<cover.1550170980.git.jonathantanmy@google.com>

The result 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.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
 remote-curl.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/remote-curl.c b/remote-curl.c
index bff0bb9af6..2eb39774d0 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -502,7 +502,6 @@ struct rpc_state {
 	int in;
 	int out;
 	int any_written;
-	struct strbuf result;
 	unsigned gzip_request : 1;
 	unsigned initial_buffer : 1;
 };
@@ -814,7 +813,8 @@ static int post_rpc(struct rpc_state *rpc)
 }
 
 static int rpc_service(struct rpc_state *rpc, struct discovery *heads,
-		       const char **client_argv, const struct strbuf *preamble)
+		       const char **client_argv, const struct strbuf *preamble,
+		       struct strbuf *rpc_result)
 {
 	const char *svc = rpc->service_name;
 	struct strbuf buf = STRBUF_INIT;
@@ -835,7 +835,6 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads,
 	rpc->buf = xmalloc(rpc->alloc);
 	rpc->in = client.in;
 	rpc->out = client.out;
-	strbuf_init(&rpc->result, 0);
 
 	strbuf_addf(&buf, "%s%s", url.buf, svc);
 	rpc->service_url = strbuf_detach(&buf, NULL);
@@ -863,7 +862,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads,
 	close(client.in);
 	client.in = -1;
 	if (!err) {
-		strbuf_read(&rpc->result, client.out, 0);
+		strbuf_read(rpc_result, client.out, 0);
 	} else {
 		char buf[4096];
 		for (;;)
@@ -916,6 +915,7 @@ static int fetch_git(struct discovery *heads,
 	struct strbuf preamble = STRBUF_INIT;
 	int i, err;
 	struct argv_array args = ARGV_ARRAY_INIT;
+	struct strbuf rpc_result = STRBUF_INIT;
 
 	argv_array_pushl(&args, "fetch-pack", "--stateless-rpc",
 			 "--stdin", "--lock-pack", NULL);
@@ -963,10 +963,10 @@ static int fetch_git(struct discovery *heads,
 	rpc.service_name = "git-upload-pack",
 	rpc.gzip_request = 1;
 
-	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);
+	err = rpc_service(&rpc, heads, args.argv, &preamble, &rpc_result);
+	if (rpc_result.len)
+		write_or_die(1, rpc_result.buf, rpc_result.len);
+	strbuf_release(&rpc_result);
 	strbuf_release(&preamble);
 	argv_array_clear(&args);
 	return err;
@@ -1061,6 +1061,7 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
 	struct argv_array args;
 	struct string_list_item *cas_option;
 	struct strbuf preamble = STRBUF_INIT;
+	struct strbuf rpc_result = STRBUF_INIT;
 
 	argv_array_init(&args);
 	argv_array_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status",
@@ -1094,10 +1095,10 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
 	memset(&rpc, 0, sizeof(rpc));
 	rpc.service_name = "git-receive-pack",
 
-	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);
+	err = rpc_service(&rpc, heads, args.argv, &preamble, &rpc_result);
+	if (rpc_result.len)
+		write_or_die(1, rpc_result.buf, rpc_result.len);
+	strbuf_release(&rpc_result);
 	strbuf_release(&preamble);
 	argv_array_clear(&args);
 	return err;
-- 
2.19.0.271.gfe8321ec05.dirty
Previous: Jonathan TanNext: Jonathan Tan
Message 4 of 24 in “Protocol v2 fix: http and auth”
  1. 0/5 Protocol v2 fix: http and authJonathan Tan, Feb 14, 2019
  2. 1/5 remote-curl: reduce scope of rpc_state.argvJonathan Tan, Feb 14, 2019
  3. 2/5 remote-curl: reduce scope of rpc_state.stdin_preambleJonathan Tan, Feb 14, 2019
  4. 3/5 remote-curl: reduce scope of rpc_state.resultJonathan Tan, Feb 14, 2019
  5. 4/5 remote-curl: refactor reading into rpc_state's bufJonathan Tan, Feb 14, 2019
  6. 5/5 remote-curl: use post_rpc() for protocol v2 alsoJonathan Tan, Feb 14, 2019
  7. Junio C HamanoFeb 14, 2019
  8. Jeff KingFeb 21, 2019
  9. Jonathan TanFeb 21, 2019
  10. Jeff KingFeb 21, 2019
  11. 0/5 Protocol v2 fix: http and authJonathan Tan, Feb 21, 2019
  12. 1/5 remote-curl: reduce scope of rpc_state.argvJonathan Tan, Feb 21, 2019
  13. 2/5 remote-curl: reduce scope of rpc_state.stdin_preambleJonathan Tan, Feb 21, 2019
  14. 3/5 remote-curl: reduce scope of rpc_state.resultJonathan Tan, Feb 21, 2019
  15. 4/5 remote-curl: refactor reading into rpc_state's bufJonathan Tan, Feb 21, 2019
  16. 5/5 remote-curl: use post_rpc() for protocol v2 alsoJonathan Tan, Feb 21, 2019
  17. Eric SunshineFeb 22, 2019
  18. Eric SunshineFeb 22, 2019
  19. Jeff KingFeb 25, 2019
  20. [FIXUP] Fixup on tip of jt/http-auth-proto-v2-fixJonathan Tan, Feb 25, 2019
  21. Jonathan NiederFeb 26, 2019
  22. Jonathan TanFeb 26, 2019
  23. Junio C HamanoMar 4, 2019
  24. Jeff KingFeb 27, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.