gpg-interface: use child_process.args
Our argv allocations are relatively straightforward, but this avoids us having to manually keep the count up to date (or create new to-be-replaced slots in the declaration) when we add new arguments. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jun 17, 2016 at 19:38 UTC
aedb5dc343be58c17dc974be401f6d2a9fa26d1e
1 file changed
+9
-10
gpg-interface.c
+9
-10
@@ -150,17 +150,15 @@ const char *get_signing_key(void)
150
int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key)
151
{
152
struct child_process gpg = CHILD_PROCESS_INIT;
153
- const char *args[4];
153
ssize_t len;
154
size_t i, j, bottom;
155
157
- gpg.argv = args;
156
gpg.in = -1;
157
gpg.out = -1;
160
- args[0] = gpg_program;
161
- args[1] = "-bsau";
162
- args[2] = signing_key;
163
- args[3] = NULL;
158
+ argv_array_pushl(&gpg.args,
159
+ gpg_program,
160
+ "-bsau", signing_key,
161
+ NULL);
162
163
if (start_command(&gpg))
164
return error(_("could not run gpg."));
@@ -210,13 +208,11 @@ int verify_signed_buffer(const char *payload, size_t payload_size,
208
struct strbuf *gpg_output, struct strbuf *gpg_status)
209
{
210
struct child_process gpg = CHILD_PROCESS_INIT;
213
- const char *args_gpg[] = {NULL, "--status-fd=1", "--verify", "FILE", "-", NULL};
211
char path[PATH_MAX];
212
int fd, ret;
213
struct strbuf buf = STRBUF_INIT;
214
struct strbuf *pbuf = &buf;
215
219
- args_gpg[0] = gpg_program;
216
fd = git_mkstemp(path, PATH_MAX, ".git_vtag_tmpXXXXXX");
217
if (fd < 0)
218
return error_errno(_("could not create temporary file '%s'"), path);
@@ -224,12 +220,15 @@ int verify_signed_buffer(const char *payload, size_t payload_size,
220
return error_errno(_("failed writing detached signature to '%s'"), path);
221
close(fd);
222
227
- gpg.argv = args_gpg;
223
+ argv_array_pushl(&gpg.args,
224
+ gpg_program,
225
+ "--status-fd=1",
226
+ "--verify", path, "-",
227
+ NULL);
228
gpg.in = -1;
229
gpg.out = -1;
230
if (gpg_output)
231
gpg.err = -1;
232
- args_gpg[3] = path;
232
if (start_command(&gpg)) {
233
unlink(path);
234
return error(_("could not run gpg."));