Thread (48 messages) 48 messages, 5 authors, 2021-11-26

Re: [PATCH 2/5] upload-archive: use regular "struct child_process" pattern

flat view

From: Jeff King <hidden>
Date: 2021-11-22 17:02:17

On Mon, Nov 22, 2021 at 05:04:04PM +0100, Ævar Arnfjörð Bjarmason wrote:
This pattern added [1] in seems to have been intentional, but since
[2] and [3] we've wanted do initialization of what's now the "struct
strvec" "args" and "env_array" members. Let's not trample on that
initialization here.
Yes, I came across this one, too, while looking at the same topic. I
think this is a good change, but:
quoted hunk ↗ jump to hunk
 int cmd_upload_archive(int argc, const char **argv, const char *prefix)
 {
-	struct child_process writer = { argv };
+	struct child_process writer = CHILD_PROCESS_INIT;
 
 	if (argc == 2 && !strcmp(argv[1], "-h"))
 		usage(upload_archive_usage);
@@ -92,6 +92,9 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
 	argv[0] = "upload-archive--writer";
You can drop this assignment over argv[0] now.
quoted hunk ↗ jump to hunk
 	writer.out = writer.err = -1;
 	writer.git_cmd = 1;
+	strvec_push(&writer.args, "upload-archive--writer");
+	if (argc > 1)
+		strvec_pushv(&writer.args, &argv[1]);
The "argc > 1" isn't necessary. If it is not true, strvec_pushv() will
see the terminating NULL in the list and just become a noop.

(I'd also spell it "argv + 1" to make it more obvious that we are
interested in the list and not a single element, but that may be a
matter of taste).

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help