Skip to content

Commit 1bc01ef

Browse files
peffgitster
authored andcommitted
upload-archive: use start_command instead of fork
The POSIX-function fork is not supported on Windows. Use our start_command API instead, respawning ourselves in a special "writer" mode to follow the alternate code path. Remove the NOT_MINGW-prereq for t5000, as git-archive --remote now works. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f56ef11 commit 1bc01ef

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
@@ -133,6 +133,7 @@ extern int cmd_update_index(int argc, const char **argv, const char *prefix);
133133
extern int cmd_update_ref(int argc, const char **argv, const char *prefix);
134134
extern int cmd_update_server_info(int argc, const char **argv, const char *prefix);
135135
extern int cmd_upload_archive(int argc, const char **argv, const char *prefix);
136+
extern int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix);
136137
extern int cmd_upload_tar(int argc, const char **argv, const char *prefix);
137138
extern int cmd_var(int argc, const char **argv, const char *prefix);
138139
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

@@ -266,7 +266,7 @@ test_expect_success 'archive --list mentions user filter' '
266266
grep "^bar\$" output
267267
'
268268

269-
test_expect_success NOT_MINGW 'archive --list shows only enabled remote filters' '
269+
test_expect_success 'archive --list shows only enabled remote filters' '
270270
git archive --list --remote=. >output &&
271271
! grep "^tar\.foo\$" output &&
272272
grep "^bar\$" output
@@ -298,7 +298,7 @@ test_expect_success 'extension matching requires dot' '
298298
test_cmp b.tar config-implicittar.foo
299299
'
300300

301-
test_expect_success NOT_MINGW 'only enabled filters are available remotely' '
301+
test_expect_success 'only enabled filters are available remotely' '
302302
test_must_fail git archive --remote=. --format=tar.foo HEAD \
303303
>remote.tar.foo &&
304304
git archive --remote=. --format=bar >remote.bar HEAD &&
@@ -341,12 +341,12 @@ test_expect_success GZIP,GUNZIP 'extract tgz file' '
341341
test_cmp b.tar j.tar
342342
'
343343

344-
test_expect_success GZIP,NOT_MINGW 'remote tar.gz is allowed by default' '
344+
test_expect_success GZIP 'remote tar.gz is allowed by default' '
345345
git archive --remote=. --format=tar.gz HEAD >remote.tar.gz &&
346346
test_cmp j.tgz remote.tar.gz
347347
'
348348

349-
test_expect_success GZIP,NOT_MINGW 'remote tar.gz can be disabled' '
349+
test_expect_success GZIP 'remote tar.gz can be disabled' '
350350
git config tar.tar.gz.remote false &&
351351
test_must_fail git archive --remote=. --format=tar.gz HEAD \
352352
>remote.tar.gz

0 commit comments

Comments
 (0)