archive: allow remote to have more formats than we understand.
This fixes git-archive --remote not to parse archiver arguments; otherwise if the remote end implements formats other than the one known locally we will not be able to access that format. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Sep 9, 2006 at 23:48 UTC
37f944363d5b5fb5bcbf2d184865534739713c01
2 files changed
+47
-33
archive.h
-1
@@ -19,7 +19,6 @@ typedef void *(*parse_extra_args_fn_t)(int argc, const char **argv);
19
20
struct archiver {
21
const char *name;
22
- const char *remote;
22
struct archiver_args args;
23
write_archive_fn_t write_archive;
24
parse_extra_args_fn_t parse_extra;
builtin-archive.c
+47
-32
@@ -26,7 +26,7 @@ struct archiver archivers[] = {
26
},
27
};
28
29
-static int run_remote_archiver(struct archiver *ar, int argc,
29
+static int run_remote_archiver(const char *remote, int argc,
30
const char **argv)
31
{
32
char *url, buf[1024];
@@ -35,16 +35,13 @@ static int run_remote_archiver(struct archiver *ar, int argc,
35
36
sprintf(buf, "git-upload-archive");
37
38
- url = xstrdup(ar->remote);
38
+ url = xstrdup(remote);
39
pid = git_connect(fd, url, buf);
40
if (pid < 0)
41
return pid;
42
43
- for (i = 1; i < argc; i++) {
44
- if (!strncmp(argv[i], "--remote=", 9))
45
- continue;
43
+ for (i = 1; i < argc; i++)
44
packet_write(fd[1], "argument %s\n", argv[i]);
47
- }
45
packet_flush(fd[1]);
46
47
len = packet_read_line(fd[0], buf, sizeof(buf));
@@ -150,17 +147,16 @@ int parse_archive_args(int argc, const char **argv, struct archiver *ar)
147
const char *extra_argv[MAX_EXTRA_ARGS];
148
int extra_argc = 0;
149
const char *format = NULL; /* might want to default to "tar" */
153
- const char *remote = NULL;
150
const char *base = "";
155
- int list = 0;
151
int i;
152
153
for (i = 1; i < argc; i++) {
154
const char *arg = argv[i];
155
156
if (!strcmp(arg, "--list") || !strcmp(arg, "-l")) {
162
- list = 1;
163
- continue;
157
+ for (i = 0; i < ARRAY_SIZE(archivers); i++)
158
+ printf("%s\n", archivers[i].name);
159
+ exit(0);
160
}
161
if (!strncmp(arg, "--format=", 9)) {
162
format = arg + 9;
@@ -170,10 +166,6 @@ int parse_archive_args(int argc, const char **argv, struct archiver *ar)
166
base = arg + 9;
167
continue;
168
}
173
- if (!strncmp(arg, "--remote=", 9)) {
174
- remote = arg + 9;
175
- continue;
176
- }
169
if (!strcmp(arg, "--")) {
170
i++;
171
break;
@@ -187,44 +179,67 @@ int parse_archive_args(int argc, const char **argv, struct archiver *ar)
179
break;
180
}
181
190
- if (list) {
191
- if (!remote) {
192
- for (i = 0; i < ARRAY_SIZE(archivers); i++)
193
- printf("%s\n", archivers[i].name);
194
- exit(0);
195
- }
196
- die("--list and --remote are mutually exclusive");
197
- }
198
-
199
- if (argc - i < 1)
182
+ /* We need at least one parameter -- tree-ish */
183
+ if (argc - 1 < i)
184
usage(archive_usage);
185
if (!format)
186
die("You must specify an archive format");
187
if (init_archiver(format, ar) < 0)
188
die("Unknown archive format '%s'", format);
189
206
- if (extra_argc && !remote) {
207
- if (!ar->parse_extra) {
190
+ if (extra_argc) {
191
+ if (!ar->parse_extra)
192
die("%s", default_parse_extra(ar, extra_argv));
209
- }
193
ar->args.extra = ar->parse_extra(extra_argc, extra_argv);
194
}
212
- ar->remote = remote;
195
ar->args.base = base;
196
197
return i;
198
}
199
200
+static const char *remote_request(int *ac, const char **av)
201
+{
202
+ int ix, iy, cnt = *ac;
203
+ int no_more_options = 0;
204
+ const char *remote = NULL;
205
+
206
+ for (ix = iy = 1; ix < cnt; ix++) {
207
+ const char *arg = av[ix];
208
+ if (!strcmp(arg, "--"))
209
+ no_more_options = 1;
210
+ if (!no_more_options) {
211
+ if (!strncmp(arg, "--remote=", 9)) {
212
+ if (remote)
213
+ die("Multiple --remote specified");
214
+ remote = arg + 9;
215
+ continue;
216
+ }
217
+ if (arg[0] != '-')
218
+ no_more_options = 1;
219
+ }
220
+ if (ix != iy)
221
+ av[iy] = arg;
222
+ iy++;
223
+ }
224
+ if (remote) {
225
+ av[--cnt] = NULL;
226
+ *ac = cnt;
227
+ }
228
+ return remote;
229
+}
230
+
231
int cmd_archive(int argc, const char **argv, const char *prefix)
232
{
233
struct archiver ar;
234
int tree_idx;
235
+ const char *remote = NULL;
236
223
- tree_idx = parse_archive_args(argc, argv, &ar);
224
-
225
- if (ar.remote)
226
- return run_remote_archiver(&ar, argc, argv);
237
+ remote = remote_request(&argc, argv);
238
+ if (remote)
239
+ return run_remote_archiver(remote, argc, argv);
240
241
+ memset(&ar, 0, sizeof(ar));
242
+ tree_idx = parse_archive_args(argc, argv, &ar);
243
if (prefix == NULL)
244
prefix = setup_git_directory();
245