2 * Copyright (c) 2006 Franck Bui-Huu
3 * Copyright (c) 2006 Rene Scharfe
11 static int run_remote_archiver(const char *remote
, int argc
,
14 char *url
, buf
[LARGE_PACKET_MAX
];
15 int fd
[2], i
, len
, rv
;
16 struct child_process
*conn
;
17 const char *exec
= "git-upload-archive";
20 for (i
= 1; i
< argc
; i
++) {
21 const char *arg
= argv
[i
];
22 if (!prefixcmp(arg
, "--exec=")) {
24 die("multiple --exec specified");
31 url
= xstrdup(remote
);
32 conn
= git_connect(fd
, url
, exec
, 0);
34 for (i
= 1; i
< argc
; i
++) {
37 packet_write(fd
[1], "argument %s\n", argv
[i
]);
41 len
= packet_read_line(fd
[0], buf
, sizeof(buf
));
43 die("git-archive: expected ACK/NAK, got EOF");
44 if (buf
[len
-1] == '\n')
46 if (strcmp(buf
, "ACK")) {
47 if (len
> 5 && !prefixcmp(buf
, "NACK "))
48 die("git-archive: NACK %s", buf
+ 5);
49 die("git-archive: protocol error");
52 len
= packet_read_line(fd
[0], buf
, sizeof(buf
));
54 die("git-archive: expected a flush");
56 /* Now, start reading from fd[0] and spit it out to stdout */
57 rv
= recv_sideband("archive", fd
[0], 1, 2);
60 rv
|= finish_connect(conn
);
65 static const char *extract_remote_arg(int *ac
, const char **av
)
67 int ix
, iy
, cnt
= *ac
;
68 int no_more_options
= 0;
69 const char *remote
= NULL
;
71 for (ix
= iy
= 1; ix
< cnt
; ix
++) {
72 const char *arg
= av
[ix
];
73 if (!strcmp(arg
, "--"))
75 if (!no_more_options
) {
76 if (!prefixcmp(arg
, "--remote=")) {
78 die("Multiple --remote specified");
96 int cmd_archive(int argc
, const char **argv
, const char *prefix
)
98 const char *remote
= NULL
;
100 remote
= extract_remote_arg(&argc
, argv
);
102 return run_remote_archiver(remote
, argc
, argv
);
104 setvbuf(stderr
, NULL
, _IOLBF
, BUFSIZ
);
106 return write_archive(argc
, argv
, prefix
, 1);