67
return NULL;
68
ext++;
69
if (!strcasecmp(ext, "zip"))
70
- return "zip";
70
+ return "--format=zip";
71
return NULL;
72
}
73
81
const char *exec = "git-upload-archive";
82
const char *output = NULL;
83
const char *remote = NULL;
84
- const char *format = NULL;
84
+ const char *format_option = NULL;
85
struct option local_opts[] = {
86
OPT_STRING('o', "output", &output, "file",
87
"write the archive to this file"),
89
"retrieve the archive from remote repository <repo>"),
90
OPT_STRING(0, "exec", &exec, "cmd",
91
"path to the remote git-upload-archive command"),
92
- OPT_STRING(0, "format", &format, "fmt", "archive format"),
92
OPT_END()
93
};
95
- char fmt_opt[32];
94
95
argc = parse_options(argc, argv, prefix, local_opts, NULL,
96
PARSE_OPT_KEEP_ALL);
97
98
if (output) {
99
create_output_file(output);
102
- if (!format)
103
- format = format_from_name(output);
100
+ format_option = format_from_name(output);
101
}
102
106
- if (format) {
107
- sprintf(fmt_opt, "--format=%s", format);
108
- /*
109
- * We have enough room in argv[] to muck it in place,
110
- * because either --format and/or --output must have
111
- * been given on the original command line if we get
112
- * to this point, and parse_options() must have eaten
113
- * it, i.e. we can add back one element to the array.
114
- * But argv[] may contain "--"; we should make it the
115
- * first option.
116
- */
103
+ /*
104
+ * We have enough room in argv[] to muck it in place, because
105
+ * --output must have been given on the original command line
106
+ * if we get to this point, and parse_options() must have eaten
107
+ * it, i.e. we can add back one element to the array.
108
+ *
109
+ * We add a fake --format option at the beginning, with the
110
+ * format inferred from our output filename. This way explicit
111
+ * --format options can override it, and the fake option is
112
+ * inserted before any "--" that might have been given.
113
+ */
114
+ if (format_option) {
115
memmove(argv + 2, argv + 1, sizeof(*argv) * argc);
118
- argv[1] = fmt_opt;
116
+ argv[1] = format_option;
117
argv[++argc] = NULL;
118
}
119