Skip to content

Commit 0bbaa5c

Browse files
committed
Merge branch 'jk/upload-archive-use-start-command'
* jk/upload-archive-use-start-command: upload-archive: use start_command instead of fork
2 parents 09bb4eb + 1bc01ef commit 0bbaa5c

File tree

4 files changed

+19
-36
lines changed

4 files changed

+19
-36
lines changed

builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ extern int cmd_update_index(int argc, const char **argv, const char *prefix);
139139
extern int cmd_update_ref(int argc, const char **argv, const char *prefix);
140140
extern int cmd_update_server_info(int argc, const char **argv, const char *prefix);
141141
extern int cmd_upload_archive(int argc, const char **argv, const char *prefix);
142+
extern int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix);
142143
extern int cmd_upload_tar(int argc, const char **argv, const char *prefix);
143144
extern int cmd_var(int argc, const char **argv, const char *prefix);
144145
extern int cmd_verify_tag(int argc, const char **argv, const char *prefix);

builtin/upload-archive.c

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@
66
#include "archive.h"
77
#include "pkt-line.h"
88
#include "sideband.h"
9+
#include "run-command.h"
910

1011
static const char upload_archive_usage[] =
1112
"git upload-archive <repo>";
1213

1314
static const char deadchild[] =
1415
"git upload-archive: archiver died with error";
1516

16-
static const char lostchild[] =
17-
"git upload-archive: archiver process was lost";
18-
1917
#define MAX_ARGS (64)
2018

21-
static int run_upload_archive(int argc, const char **argv, const char *prefix)
19+
int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
2220
{
2321
const char *sent_argv[MAX_ARGS];
2422
const char *arg_cmd = "argument ";
@@ -96,48 +94,33 @@ static ssize_t process_input(int child_fd, int band)
9694

9795
int cmd_upload_archive(int argc, const char **argv, const char *prefix)
9896
{
99-
pid_t writer;
100-
int fd1[2], fd2[2];
97+
struct child_process writer = { argv };
98+
10199
/*
102100
* Set up sideband subprocess.
103101
*
104102
* We (parent) monitor and read from child, sending its fd#1 and fd#2
105103
* multiplexed out to our fd#1. If the child dies, we tell the other
106104
* end over channel #3.
107105
*/
108-
if (pipe(fd1) < 0 || pipe(fd2) < 0) {
109-
int err = errno;
110-
packet_write(1, "NACK pipe failed on the remote side\n");
111-
die("upload-archive: %s", strerror(err));
112-
}
113-
writer = fork();
114-
if (writer < 0) {
106+
argv[0] = "upload-archive--writer";
107+
writer.out = writer.err = -1;
108+
writer.git_cmd = 1;
109+
if (start_command(&writer)) {
115110
int err = errno;
116-
packet_write(1, "NACK fork failed on the remote side\n");
111+
packet_write(1, "NACK unable to spawn subprocess\n");
117112
die("upload-archive: %s", strerror(err));
118113
}
119-
if (!writer) {
120-
/* child - connect fd#1 and fd#2 to the pipe */
121-
dup2(fd1[1], 1);
122-
dup2(fd2[1], 2);
123-
close(fd1[1]); close(fd2[1]);
124-
close(fd1[0]); close(fd2[0]); /* we do not read from pipe */
125-
126-
exit(run_upload_archive(argc, argv, prefix));
127-
}
128114

129-
/* parent - read from child, multiplex and send out to fd#1 */
130-
close(fd1[1]); close(fd2[1]); /* we do not write to pipe */
131115
packet_write(1, "ACK\n");
132116
packet_flush(1);
133117

134118
while (1) {
135119
struct pollfd pfd[2];
136-
int status;
137120

138-
pfd[0].fd = fd1[0];
121+
pfd[0].fd = writer.out;
139122
pfd[0].events = POLLIN;
140-
pfd[1].fd = fd2[0];
123+
pfd[1].fd = writer.err;
141124
pfd[1].events = POLLIN;
142125
if (poll(pfd, 2, -1) < 0) {
143126
if (errno != EINTR) {
@@ -156,9 +139,7 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
156139
if (process_input(pfd[0].fd, 1))
157140
continue;
158141

159-
if (waitpid(writer, &status, 0) < 0)
160-
error_clnt("%s", lostchild);
161-
else if (!WIFEXITED(status) || WEXITSTATUS(status) > 0)
142+
if (finish_command(&writer))
162143
error_clnt("%s", deadchild);
163144
packet_flush(1);
164145
break;

git.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ static void handle_internal_command(int argc, const char **argv)
434434
{ "update-ref", cmd_update_ref, RUN_SETUP },
435435
{ "update-server-info", cmd_update_server_info, RUN_SETUP },
436436
{ "upload-archive", cmd_upload_archive },
437+
{ "upload-archive--writer", cmd_upload_archive_writer },
437438
{ "var", cmd_var, RUN_SETUP_GENTLY },
438439
{ "verify-pack", cmd_verify_pack },
439440
{ "verify-tag", cmd_verify_tag, RUN_SETUP },

t/t5000-tar-tree.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ test_expect_success 'git archive with --output' \
9696
'git archive --output=b4.tar HEAD &&
9797
test_cmp b.tar b4.tar'
9898

99-
test_expect_success NOT_MINGW 'git archive --remote' \
99+
test_expect_success 'git archive --remote' \
100100
'git archive --remote=. HEAD >b5.tar &&
101101
test_cmp b.tar b5.tar'
102102

@@ -274,7 +274,7 @@ test_expect_success 'archive --list mentions user filter' '
274274
grep "^bar\$" output
275275
'
276276

277-
test_expect_success NOT_MINGW 'archive --list shows only enabled remote filters' '
277+
test_expect_success 'archive --list shows only enabled remote filters' '
278278
git archive --list --remote=. >output &&
279279
! grep "^tar\.foo\$" output &&
280280
grep "^bar\$" output
@@ -306,7 +306,7 @@ test_expect_success 'extension matching requires dot' '
306306
test_cmp b.tar config-implicittar.foo
307307
'
308308

309-
test_expect_success NOT_MINGW 'only enabled filters are available remotely' '
309+
test_expect_success 'only enabled filters are available remotely' '
310310
test_must_fail git archive --remote=. --format=tar.foo HEAD \
311311
>remote.tar.foo &&
312312
git archive --remote=. --format=bar >remote.bar HEAD &&
@@ -349,12 +349,12 @@ test_expect_success GZIP,GUNZIP 'extract tgz file' '
349349
test_cmp b.tar j.tar
350350
'
351351

352-
test_expect_success GZIP,NOT_MINGW 'remote tar.gz is allowed by default' '
352+
test_expect_success GZIP 'remote tar.gz is allowed by default' '
353353
git archive --remote=. --format=tar.gz HEAD >remote.tar.gz &&
354354
test_cmp j.tgz remote.tar.gz
355355
'
356356

357-
test_expect_success GZIP,NOT_MINGW 'remote tar.gz can be disabled' '
357+
test_expect_success GZIP 'remote tar.gz can be disabled' '
358358
git config tar.tar.gz.remote false &&
359359
test_must_fail git archive --remote=. --format=tar.gz HEAD \
360360
>remote.tar.gz

0 commit comments

Comments
 (0)