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";
18 int exec_at
= 0, exec_value_at
= 0;
20 for (i
= 1; i
< argc
; i
++) {
21 const char *arg
= argv
[i
];
22 if (!prefixcmp(arg
, "--exec=")) {
24 die("multiple --exec specified");
27 } else if (!strcmp(arg
, "--exec")) {
29 die("multiple --exec specified");
31 die("option --exec requires a value");
38 url
= xstrdup(remote
);
39 conn
= git_connect(fd
, url
, exec
, 0);
41 for (i
= 1; i
< argc
; i
++) {
42 if (i
== exec_at
|| i
== exec_value_at
)
44 packet_write(fd
[1], "argument %s\n", argv
[i
]);
48 len
= packet_read_line(fd
[0], buf
, sizeof(buf
));
50 die("git archive: expected ACK/NAK, got EOF");
51 if (buf
[len
-1] == '\n')
53 if (strcmp(buf
, "ACK")) {
54 if (len
> 5 && !prefixcmp(buf
, "NACK "))
55 die("git archive: NACK %s", buf
+ 5);
56 die("git archive: protocol error");
59 len
= packet_read_line(fd
[0], buf
, sizeof(buf
));
61 die("git archive: expected a flush");
63 /* Now, start reading from fd[0] and spit it out to stdout */
64 rv
= recv_sideband("archive", fd
[0], 1, 2);
67 rv
|= finish_connect(conn
);
72 static const char *extract_remote_arg(int *ac
, const char **av
)
74 int ix
, iy
, cnt
= *ac
;
75 int no_more_options
= 0;
76 const char *remote
= NULL
;
78 for (ix
= iy
= 1; ix
< cnt
; ix
++) {
79 const char *arg
= av
[ix
];
80 if (!strcmp(arg
, "--"))
82 if (!no_more_options
) {
83 if (!prefixcmp(arg
, "--remote=")) {
85 die("Multiple --remote specified");
88 } else if (!strcmp(arg
, "--remote")) {
90 die("Multiple --remote specified");
92 die("option --remote requires a value");
110 int cmd_archive(int argc
, const char **argv
, const char *prefix
)
112 const char *remote
= NULL
;
114 git_config(git_default_config
, NULL
);
116 remote
= extract_remote_arg(&argc
, argv
);
118 return run_remote_archiver(remote
, argc
, argv
);
120 setvbuf(stderr
, NULL
, _IOLBF
, BUFSIZ
);
122 return write_archive(argc
, argv
, prefix
, 1);