* [PATCH] http: use internal argv_array of struct child_process
@ 2017-12-22 8:14 René Scharfe
2017-12-22 8:59 ` Eric Sunshine
0 siblings, 1 reply; 3+ messages in thread
From: René Scharfe @ 2017-12-22 8:14 UTC (permalink / raw)
To: Git List; +Cc: Junio C Hamano
Avoid a strangely magic array size (it's slightly too big) and explicit
index numbers by building the command line for index-pack using the
embedded argv_array of the child_process. The resulting code is shorter
and easier to extend.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
http.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/http.c b/http.c
index 215bebef1b..b22b4ada58 100644
--- a/http.c
+++ b/http.c
@@ -2025,7 +2025,6 @@ int finish_http_pack_request(struct http_pack_request *preq)
char *tmp_idx;
size_t len;
struct child_process ip = CHILD_PROCESS_INIT;
- const char *ip_argv[8];
close_pack_index(p);
@@ -2041,13 +2040,10 @@ int finish_http_pack_request(struct http_pack_request *preq)
die("BUG: pack tmpfile does not end in .pack.temp?");
tmp_idx = xstrfmt("%.*s.idx.temp", (int)len, preq->tmpfile);
- ip_argv[0] = "index-pack";
- ip_argv[1] = "-o";
- ip_argv[2] = tmp_idx;
- ip_argv[3] = preq->tmpfile;
- ip_argv[4] = NULL;
-
- ip.argv = ip_argv;
+ argv_array_push(&ip.args, "index-pack");
+ argv_array_push(&ip.args, "-o");
+ argv_array_push(&ip.args, tmp_idx);
+ argv_array_push(&ip.args, preq->tmpfile);
ip.git_cmd = 1;
ip.no_stdin = 1;
ip.no_stdout = 1;
--
2.15.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] http: use internal argv_array of struct child_process
2017-12-22 8:14 [PATCH] http: use internal argv_array of struct child_process René Scharfe
@ 2017-12-22 8:59 ` Eric Sunshine
2017-12-22 11:56 ` [PATCH v2] " René Scharfe
0 siblings, 1 reply; 3+ messages in thread
From: Eric Sunshine @ 2017-12-22 8:59 UTC (permalink / raw)
To: René Scharfe; +Cc: Git List, Junio C Hamano
On Fri, Dec 22, 2017 at 3:14 AM, René Scharfe <l.s.r@web.de> wrote:
> Avoid a strangely magic array size (it's slightly too big) and explicit
> index numbers by building the command line for index-pack using the
> embedded argv_array of the child_process. The resulting code is shorter
> and easier to extend.
>
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
> diff --git a/http.c b/http.c
> @@ -2041,13 +2040,10 @@ int finish_http_pack_request(struct http_pack_request *preq)
> - ip_argv[0] = "index-pack";
> - ip_argv[1] = "-o";
> - ip_argv[2] = tmp_idx;
> - ip_argv[3] = preq->tmpfile;
> - ip_argv[4] = NULL;
> -
> - ip.argv = ip_argv;
> + argv_array_push(&ip.args, "index-pack");
> + argv_array_push(&ip.args, "-o");
> + argv_array_push(&ip.args, tmp_idx);
> + argv_array_push(&ip.args, preq->tmpfile);
Not necessarily worth a re-roll, but using the "pushl" variant would
make it clear that "-o" and tmp_idx are related and would ensure that
they don't accidentally get split up if someone inserts a new "push"
in the sequence in the future.
argv_array_push(&ip.args, "index-pack");
argv_array_pushl(&ip.args, "-o", tmp_idx, NULL);
argv_array_push(&ip.args, preq->tmpfile);
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2] http: use internal argv_array of struct child_process
2017-12-22 8:59 ` Eric Sunshine
@ 2017-12-22 11:56 ` René Scharfe
0 siblings, 0 replies; 3+ messages in thread
From: René Scharfe @ 2017-12-22 11:56 UTC (permalink / raw)
To: Git List; +Cc: Eric Sunshine, Junio C Hamano
Avoid a strangely magic array size (it's slightly too big) and explicit
index numbers by building the command line for index-pack using the
embedded argv_array of the child_process. Add the flag -o and its
argument with argv_array_pushl() to make it obvious that they belong
together. The resulting code is shorter and easier to extend.
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
Change from v1: use argv_array_pushl for -o and tmp_idx.
Thanks, Eric, good idea!
http.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/http.c b/http.c
index 215bebef1b..9f2fcc9ec4 100644
--- a/http.c
+++ b/http.c
@@ -2025,7 +2025,6 @@ int finish_http_pack_request(struct http_pack_request *preq)
char *tmp_idx;
size_t len;
struct child_process ip = CHILD_PROCESS_INIT;
- const char *ip_argv[8];
close_pack_index(p);
@@ -2041,13 +2040,9 @@ int finish_http_pack_request(struct http_pack_request *preq)
die("BUG: pack tmpfile does not end in .pack.temp?");
tmp_idx = xstrfmt("%.*s.idx.temp", (int)len, preq->tmpfile);
- ip_argv[0] = "index-pack";
- ip_argv[1] = "-o";
- ip_argv[2] = tmp_idx;
- ip_argv[3] = preq->tmpfile;
- ip_argv[4] = NULL;
-
- ip.argv = ip_argv;
+ argv_array_push(&ip.args, "index-pack");
+ argv_array_pushl(&ip.args, "-o", tmp_idx, NULL);
+ argv_array_push(&ip.args, preq->tmpfile);
ip.git_cmd = 1;
ip.no_stdin = 1;
ip.no_stdout = 1;
--
2.15.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-12-22 11:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-22 8:14 [PATCH] http: use internal argv_array of struct child_process René Scharfe
2017-12-22 8:59 ` Eric Sunshine
2017-12-22 11:56 ` [PATCH v2] " René Scharfe
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).