Skip to content

Commit 5267fa3

Browse files
committed
Merge branch 'ef/mingw-upload-archive' into next
* ef/mingw-upload-archive: upload-archive: use start_command instead of fork compat/win32/poll.c: upgrade from upstream mingw: move poll out of sys-folder
2 parents 2527a49 + c09cd77 commit 5267fa3

File tree

7 files changed

+48
-63
lines changed

7 files changed

+48
-63
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,7 @@ ifeq ($(uname_S),Windows)
10911091
NO_PREAD = YesPlease
10921092
NEEDS_CRYPTO_WITH_SSL = YesPlease
10931093
NO_LIBGEN_H = YesPlease
1094+
NO_SYS_POLL_H = YesPlease
10941095
NO_SYMLINK_HEAD = YesPlease
10951096
NO_IPV6 = YesPlease
10961097
NO_SETENV = YesPlease
@@ -1129,7 +1130,7 @@ ifeq ($(uname_S),Windows)
11291130
BASIC_CFLAGS = -nologo -I. -I../zlib -Icompat/vcbuild -Icompat/vcbuild/include -DWIN32 -D_CONSOLE -DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE
11301131
COMPAT_OBJS = compat/msvc.o compat/winansi.o \
11311132
compat/win32/pthread.o compat/win32/syslog.o \
1132-
compat/win32/sys/poll.o compat/win32/dirent.o
1133+
compat/win32/poll.o compat/win32/dirent.o
11331134
COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
11341135
BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE -NODEFAULTLIB:MSVCRT.lib
11351136
EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib
@@ -1184,6 +1185,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
11841185
NO_PREAD = YesPlease
11851186
NEEDS_CRYPTO_WITH_SSL = YesPlease
11861187
NO_LIBGEN_H = YesPlease
1188+
NO_SYS_POLL_H = YesPlease
11871189
NO_SYMLINK_HEAD = YesPlease
11881190
NO_SETENV = YesPlease
11891191
NO_UNSETENV = YesPlease
@@ -1217,7 +1219,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
12171219
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
12181220
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
12191221
compat/win32/pthread.o compat/win32/syslog.o \
1220-
compat/win32/sys/poll.o compat/win32/dirent.o
1222+
compat/win32/poll.o compat/win32/dirent.o
12211223
EXTLIBS += -lws2_32
12221224
PTHREAD_LIBS =
12231225
X = .exe

builtin/archive.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,17 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
8787
const char *exec = "git-upload-archive";
8888
const char *output = NULL;
8989
const char *remote = NULL;
90+
int is_remote = 0;
9091
struct option local_opts[] = {
9192
OPT_STRING('o', "output", &output, "file",
9293
"write the archive to this file"),
9394
OPT_STRING(0, "remote", &remote, "repo",
9495
"retrieve the archive from remote repository <repo>"),
9596
OPT_STRING(0, "exec", &exec, "cmd",
9697
"path to the remote git-upload-archive command"),
98+
{ OPTION_BOOLEAN, 0, "remote-request", &is_remote, NULL,
99+
"indicate we are serving a remote request",
100+
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
97101
OPT_END()
98102
};
99103

@@ -108,5 +112,5 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
108112

109113
setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
110114

111-
return write_archive(argc, argv, prefix, 1, output, 0);
115+
return write_archive(argc, argv, prefix, 1, output, is_remote);
112116
}

builtin/upload-archive.c

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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>";
@@ -18,28 +19,17 @@ static const char lostchild[] =
1819

1920
#define MAX_ARGS (64)
2021

21-
static int run_upload_archive(int argc, const char **argv, const char *prefix)
22+
static void prepare_argv(const char **sent_argv, const char **argv)
2223
{
23-
const char *sent_argv[MAX_ARGS];
2424
const char *arg_cmd = "argument ";
2525
char *p, buf[4096];
2626
int sent_argc;
2727
int len;
2828

29-
if (argc != 2)
30-
usage(upload_archive_usage);
31-
32-
if (strlen(argv[1]) + 1 > sizeof(buf))
33-
die("insanely long repository name");
34-
35-
strcpy(buf, argv[1]); /* enter-repo smudges its argument */
36-
37-
if (!enter_repo(buf, 0))
38-
die("'%s' does not appear to be a git repository", buf);
39-
4029
/* put received options in sent_argv[] */
41-
sent_argc = 1;
42-
sent_argv[0] = "git-upload-archive";
30+
sent_argc = 2;
31+
sent_argv[0] = "archive";
32+
sent_argv[1] = "--remote-request";
4333
for (p = buf;;) {
4434
/* This will die if not enough free space in buf */
4535
len = packet_read_line(0, p, (buf + sizeof buf) - p);
@@ -62,9 +52,6 @@ static int run_upload_archive(int argc, const char **argv, const char *prefix)
6252
*p++ = 0;
6353
}
6454
sent_argv[sent_argc] = NULL;
65-
66-
/* parse all options sent by the client */
67-
return write_archive(sent_argc, sent_argv, prefix, 0, NULL, 1);
6855
}
6956

7057
__attribute__((format (printf, 1, 2)))
@@ -96,48 +83,35 @@ static ssize_t process_input(int child_fd, int band)
9683

9784
int cmd_upload_archive(int argc, const char **argv, const char *prefix)
9885
{
99-
pid_t writer;
100-
int fd1[2], fd2[2];
101-
/*
102-
* Set up sideband subprocess.
103-
*
104-
* We (parent) monitor and read from child, sending its fd#1 and fd#2
105-
* multiplexed out to our fd#1. If the child dies, we tell the other
106-
* end over channel #3.
107-
*/
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) {
86+
const char *sent_argv[MAX_ARGS];
87+
struct child_process cld = { sent_argv };
88+
cld.out = cld.err = -1;
89+
cld.git_cmd = 1;
90+
91+
if (argc != 2)
92+
usage(upload_archive_usage);
93+
94+
if (!enter_repo(argv[1], 0))
95+
die("'%s' does not appear to be a git repository", argv[1]);
96+
97+
prepare_argv(sent_argv, argv);
98+
if (start_command(&cld)) {
11599
int err = errno;
116100
packet_write(1, "NACK fork failed on the remote side\n");
117101
die("upload-archive: %s", strerror(err));
118102
}
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-
}
128103

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

134108
while (1) {
135109
struct pollfd pfd[2];
136110
int status;
137111

138-
pfd[0].fd = fd1[0];
112+
pfd[0].fd = cld.out;
139113
pfd[0].events = POLLIN;
140-
pfd[1].fd = fd2[0];
114+
pfd[1].fd = cld.err;
141115
pfd[1].events = POLLIN;
142116
if (poll(pfd, 2, -1) < 0) {
143117
if (errno != EINTR) {
@@ -156,7 +130,7 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
156130
if (process_input(pfd[0].fd, 1))
157131
continue;
158132

159-
if (waitpid(writer, &status, 0) < 0)
133+
if (waitpid(cld.pid, &status, 0) < 0)
160134
error_clnt("%s", lostchild);
161135
else if (!WIFEXITED(status) || WEXITSTATUS(status) > 0)
162136
error_clnt("%s", deadchild);

compat/mingw.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ static inline int symlink(const char *oldpath, const char *newpath)
8585
{ errno = ENOSYS; return -1; }
8686
static inline int fchmod(int fildes, mode_t mode)
8787
{ errno = ENOSYS; return -1; }
88-
static inline pid_t fork(void)
89-
{ errno = ENOSYS; return -1; }
9088
static inline unsigned int alarm(unsigned int seconds)
9189
{ return 0; }
9290
static inline int fsync(int fd)
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Emulation for poll(2)
22
Contributed by Paolo Bonzini.
33
4-
Copyright 2001-2003, 2006-2010 Free Software Foundation, Inc.
4+
Copyright 2001-2003, 2006-2011 Free Software Foundation, Inc.
55
66
This file is part of gnulib.
77
@@ -27,7 +27,10 @@
2727
#include <malloc.h>
2828

2929
#include <sys/types.h>
30-
#include "poll.h"
30+
31+
/* Specification. */
32+
#include <poll.h>
33+
3134
#include <errno.h>
3235
#include <limits.h>
3336
#include <assert.h>
@@ -314,10 +317,7 @@ compute_revents (int fd, int sought, fd_set *rfds, fd_set *wfds, fd_set *efds)
314317
#endif /* !MinGW */
315318

316319
int
317-
poll (pfd, nfd, timeout)
318-
struct pollfd *pfd;
319-
nfds_t nfd;
320-
int timeout;
320+
poll (struct pollfd *pfd, nfds_t nfd, int timeout)
321321
{
322322
#ifndef WIN32_NATIVE
323323
fd_set rfds, wfds, efds;
@@ -454,6 +454,7 @@ poll (pfd, nfd, timeout)
454454
if (!hEvent)
455455
hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
456456

457+
restart:
457458
handle_array[0] = hEvent;
458459
nhandles = 1;
459460
FD_ZERO (&rfds);
@@ -594,6 +595,12 @@ poll (pfd, nfd, timeout)
594595
rc++;
595596
}
596597

598+
if (!rc && timeout == INFTIM)
599+
{
600+
SwitchToThread();
601+
goto restart;
602+
}
603+
597604
return rc;
598605
#endif
599606
}

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)