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

[PATCH v2 1/7] remote-curl: pass "struct strvec *" instead of int/char ** pair

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Sep 12, 2021, 00:15 UTC
Message-ID
<patch-v2-1.7-2ef48d734e8-20210912T001420Z-avarab@gmail.com>
In-Reply-To
<cover-v2-0.7-00000000000-20210912T001420Z-avarab@gmail.com>

We'll be changing the "int nr" in the "struct strvec" to "int size_t" soon, i.e. from signed to unsigned. It will then make sense to use the "size_t" type for things that mirror that "nr" member.

This sets up that change in remote-curl.c, we'll change the "int i" here to a "size_t i" in a later commit (let's also split and "err" up to make that change smaller).

In this case the push() function can just pass the "struct strvec" it has down to push_dav() and push_git(), in addition make use of strvec_pushv() in push_dav() instead of looping over the the specs ourselves. So we can get rid of much of the need for tracking the "nr", which in the case of push_dav() was already a "size_t".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 remote-curl.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/remote-curl.c b/remote-curl.c
index 598cff7cde6..1f177e86f11 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1266,10 +1266,9 @@ static void parse_fetch(struct strbuf *buf)
 	strbuf_reset(buf);
 }
 
-static int push_dav(int nr_spec, const char **specs)
+static int push_dav(struct strvec *specs)
 {
 	struct child_process child = CHILD_PROCESS_INIT;
-	size_t i;
 
 	child.git_cmd = 1;
 	strvec_push(&child.args, "http-push");
@@ -1279,18 +1278,18 @@ static int push_dav(int nr_spec, const char **specs)
 	if (options.verbosity > 1)
 		strvec_push(&child.args, "--verbose");
 	strvec_push(&child.args, url.buf);
-	for (i = 0; i < nr_spec; i++)
-		strvec_push(&child.args, specs[i]);
+	strvec_pushv(&child.args, specs->v);
 
 	if (run_command(&child))
 		die(_("git-http-push failed"));
 	return 0;
 }
 
-static int push_git(struct discovery *heads, int nr_spec, const char **specs)
+static int push_git(struct discovery *heads, struct strvec *specs)
 {
 	struct rpc_state rpc;
-	int i, err;
+	int i;
+	int err;
 	struct strvec args;
 	struct string_list_item *cas_option;
 	struct strbuf preamble = STRBUF_INIT;
@@ -1326,8 +1325,8 @@ static int push_git(struct discovery *heads, int nr_spec, const char **specs)
 		strvec_push(&args, "--force-if-includes");
 
 	strvec_push(&args, "--stdin");
-	for (i = 0; i < nr_spec; i++)
-		packet_buf_write(&preamble, "%s\n", specs[i]);
+	for (i = 0; i < specs->nr; i++)
+		packet_buf_write(&preamble, "%s\n", specs->v[i]);
 	packet_buf_flush(&preamble);
 
 	memset(&rpc, 0, sizeof(rpc));
@@ -1342,15 +1341,15 @@ static int push_git(struct discovery *heads, int nr_spec, const char **specs)
 	return err;
 }
 
-static int push(int nr_spec, const char **specs)
+static int push(struct strvec *specs)
 {
 	struct discovery *heads = discover_refs("git-receive-pack", 1);
 	int ret;
 
 	if (heads->proto_git)
-		ret = push_git(heads, nr_spec, specs);
+		ret = push_git(heads, specs);
 	else
-		ret = push_dav(nr_spec, specs);
+		ret = push_dav(specs);
 	free_discovery(heads);
 	return ret;
 }
@@ -1374,7 +1373,7 @@ static void parse_push(struct strbuf *buf)
 			break;
 	} while (1);
 
-	ret = push(specs.nr, specs.v);
+	ret = push(&specs);
 	printf("\n");
 	fflush(stdout);
 
-- 
2.33.0.998.ga4d44345d43
Previous: Ævar Arnfjörð BjarmasonNext: Carlo Arenas
Message 5 of 23 in “strvec: use size_t to store nr and alloc”
  1. strvec: use size_t to store nr and allocJeff King, Sep 11, 2021
  2. Ævar Arnfjörð BjarmasonSep 11, 2021
  3. Philip OakleySep 11, 2021
  4. 0/7 strvec: use size_t to store nr and allocÆvar Arnfjörð Bjarmason, Sep 12, 2021
  5. 1/7 remote-curl: pass "struct strvec *" instead of int/char ** pairÆvar Arnfjörð Bjarmason, Sep 12, 2021
  6. Carlo ArenasSep 12, 2021
  7. Ævar Arnfjörð BjarmasonSep 13, 2021
  8. 2/7 pack-objects: pass "struct strvec *" instead of int/char ** pairÆvar Arnfjörð Bjarmason, Sep 12, 2021
  9. 3/7 sequencer.[ch]: pass "struct strvec *" instead of int/char ** pairÆvar Arnfjörð Bjarmason, Sep 12, 2021
  10. 4/7 upload-pack.c: pass "struct strvec *" instead of int/char ** pairÆvar Arnfjörð Bjarmason, Sep 12, 2021
  11. 5/7 rebase: don't have loop over "struct strvec" depend on signed "nr"Ævar Arnfjörð Bjarmason, Sep 12, 2021
  12. Eric SunshineSep 12, 2021
  13. 6/7 strvec: use size_t to store nr and allocÆvar Arnfjörð Bjarmason, Sep 12, 2021
  14. 7/7 strvec API users: change some "int" tracking "nr" to "size_t"Ævar Arnfjörð Bjarmason, Sep 12, 2021
  15. Eric SunshineSep 12, 2021
  16. Jeff KingSep 12, 2021
  17. Junio C HamanoSep 13, 2021
  18. Ævar Arnfjörð BjarmasonSep 13, 2021
  19. Jeff KingSep 13, 2021
  20. Philip OakleySep 13, 2021
  21. Jeff KingSep 12, 2021
  22. Philip OakleySep 13, 2021
  23. Jeff KingSep 12, 2021

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.