Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
run-command: introduce child_process_init()
author
René Scharfe
<l.s.r@web.de>
Tue, 19 Aug 2014 19:10:48 +0000
(21:10 +0200)
committer
Junio C Hamano
<gitster@pobox.com>
Wed, 20 Aug 2014 16:54:58 +0000
(09:54 -0700)
Add a helper function for initializing those struct child_process
variables for which the macro CHILD_PROCESS_INIT can't be used.
Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/technical/api-run-command.txt
patch
|
blob
|
history
connect.c
patch
|
blob
|
history
run-command.c
patch
|
blob
|
history
run-command.h
patch
|
blob
|
history
transport-helper.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
d318027
)
diff --git
a/Documentation/technical/api-run-command.txt
b/Documentation/technical/api-run-command.txt
index ca066bfe3774b37c572e415b1cce085ee5f3768d..842b8389eb867b6db654cf7fe29e8f10b92b259e 100644
(file)
--- a/
Documentation/technical/api-run-command.txt
+++ b/
Documentation/technical/api-run-command.txt
@@
-13,6
+13,10
@@
produces in the caller in order to process it.
Functions
---------
Functions
---------
+`child_process_init`
+
+ Initialize a struct child_process variable.
+
`start_command`::
Start a sub-process. Takes a pointer to a `struct child_process`
`start_command`::
Start a sub-process. Takes a pointer to a `struct child_process`
@@
-96,8
+100,8
@@
command to run in a sub-process.
The caller:
The caller:
-1. allocates and clears (
memset(&chld, 0, sizeof(chld));
or
-
using
CHILD_PROCESS_INIT) a struct child_process variable;
+1. allocates and clears (
using child_process_init()
or
+ CHILD_PROCESS_INIT) a struct child_process variable;
2. initializes the members;
3. calls start_command();
4. processes the data;
2. initializes the members;
3. calls start_command();
4. processes the data;
diff --git
a/connect.c
b/connect.c
index f5b930a2699c31bc861505d3bd46a4dacf709cf0..87b52026326e8c0f0296e80d64c784888f719a8e 100644
(file)
--- a/
connect.c
+++ b/
connect.c
@@
-537,7
+537,8
@@
static struct child_process *git_proxy_connect(int fd[2], char *host)
get_host_and_port(&host, &port);
get_host_and_port(&host, &port);
- proxy = xcalloc(1, sizeof(*proxy));
+ proxy = xmalloc(sizeof(*proxy));
+ child_process_init(proxy);
argv_array_push(&proxy->args, git_proxy_command);
argv_array_push(&proxy->args, host);
argv_array_push(&proxy->args, port);
argv_array_push(&proxy->args, git_proxy_command);
argv_array_push(&proxy->args, host);
argv_array_push(&proxy->args, port);
@@
-694,7
+695,8
@@
struct child_process *git_connect(int fd[2], const char *url,
target_host, 0);
free(target_host);
} else {
target_host, 0);
free(target_host);
} else {
- conn = xcalloc(1, sizeof(*conn));
+ conn = xmalloc(sizeof(*conn));
+ child_process_init(conn);
strbuf_addstr(&cmd, prog);
strbuf_addch(&cmd, ' ');
strbuf_addstr(&cmd, prog);
strbuf_addch(&cmd, ' ');
diff --git
a/run-command.c
b/run-command.c
index a29a34fb1d0f5737a0db0aa7f02252cac324b378..47ab21bcc3811b23d1b1e5e59941b17aa2757558 100644
(file)
--- a/
run-command.c
+++ b/
run-command.c
@@
-8,6
+8,12
@@
# define SHELL_PATH "/bin/sh"
#endif
# define SHELL_PATH "/bin/sh"
#endif
+void child_process_init(struct child_process *child)
+{
+ memset(child, 0, sizeof(*child));
+ argv_array_init(&child->args);
+}
+
struct child_to_clean {
pid_t pid;
struct child_to_clean *next;
struct child_to_clean {
pid_t pid;
struct child_to_clean *next;
diff --git
a/run-command.h
b/run-command.h
index 5484400aa6044a6c24ab444ebf0af06404863712..1b135d1c960aa58e2fa4ad44ecc195835daac69a 100644
(file)
--- a/
run-command.h
+++ b/
run-command.h
@@
-45,6
+45,7
@@
struct child_process {
};
#define CHILD_PROCESS_INIT { NULL, ARGV_ARRAY_INIT }
};
#define CHILD_PROCESS_INIT { NULL, ARGV_ARRAY_INIT }
+void child_process_init(struct child_process *);
int start_command(struct child_process *);
int finish_command(struct child_process *);
int start_command(struct child_process *);
int finish_command(struct child_process *);
diff --git
a/transport-helper.c
b/transport-helper.c
index 3d8fe7d801293a338f13dfd01ba352e84c658813..080a7a6ae23e6915c425a3e471fd641aabafba90 100644
(file)
--- a/
transport-helper.c
+++ b/
transport-helper.c
@@
-118,7
+118,8
@@
static struct child_process *get_helper(struct transport *transport)
if (data->helper)
return data->helper;
if (data->helper)
return data->helper;
- helper = xcalloc(1, sizeof(*helper));
+ helper = xmalloc(sizeof(*helper));
+ child_process_init(helper);
helper->in = -1;
helper->out = -1;
helper->err = 0;
helper->in = -1;
helper->out = -1;
helper->err = 0;
@@
-395,7
+396,7
@@
static int get_importer(struct transport *transport, struct child_process *fasti
struct child_process *helper = get_helper(transport);
struct helper_data *data = transport->data;
int cat_blob_fd, code;
struct child_process *helper = get_helper(transport);
struct helper_data *data = transport->data;
int cat_blob_fd, code;
-
memset(fastimport, 0, sizeof(*fastimport)
);
+
child_process_init(fastimport
);
fastimport->in = helper->out;
argv_array_push(&fastimport->args, "fast-import");
argv_array_push(&fastimport->args, debug ? "--stats" : "--quiet");
fastimport->in = helper->out;
argv_array_push(&fastimport->args, "fast-import");
argv_array_push(&fastimport->args, debug ? "--stats" : "--quiet");