Skip to content

Commit aedb5dc

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 05219a1 commit aedb5dc

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

gpg-interface.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,15 @@ const char *get_signing_key(void)
150150
int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key)
151151
{
152152
struct child_process gpg = CHILD_PROCESS_INIT;
153-
const char *args[4];
154153
ssize_t len;
155154
size_t i, j, bottom;
156155

157-
gpg.argv = args;
158156
gpg.in = -1;
159157
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);
164162

165163
if (start_command(&gpg))
166164
return error(_("could not run gpg."));
@@ -210,26 +208,27 @@ int verify_signed_buffer(const char *payload, size_t payload_size,
210208
struct strbuf *gpg_output, struct strbuf *gpg_status)
211209
{
212210
struct child_process gpg = CHILD_PROCESS_INIT;
213-
const char *args_gpg[] = {NULL, "--status-fd=1", "--verify", "FILE", "-", NULL};
214211
char path[PATH_MAX];
215212
int fd, ret;
216213
struct strbuf buf = STRBUF_INIT;
217214
struct strbuf *pbuf = &buf;
218215

219-
args_gpg[0] = gpg_program;
220216
fd = git_mkstemp(path, PATH_MAX, ".git_vtag_tmpXXXXXX");
221217
if (fd < 0)
222218
return error_errno(_("could not create temporary file '%s'"), path);
223219
if (write_in_full(fd, signature, signature_size) < 0)
224220
return error_errno(_("failed writing detached signature to '%s'"), path);
225221
close(fd);
226222

227-
gpg.argv = args_gpg;
223+
argv_array_pushl(&gpg.args,
224+
gpg_program,
225+
"--status-fd=1",
226+
"--verify", path, "-",
227+
NULL);
228228
gpg.in = -1;
229229
gpg.out = -1;
230230
if (gpg_output)
231231
gpg.err = -1;
232-
args_gpg[3] = path;
233232
if (start_command(&gpg)) {
234233
unlink(path);
235234
return error(_("could not run gpg."));

0 commit comments

Comments
 (0)